2016-04-06 17 views
0

我移植了咕嘟咕嘟入門Rails的助手中間人,但我得到以下錯誤:Rails的幫手'象徵的隱式轉換成String`

no implicit conversion of Symbol into String相關Ruby /middleman-gulp-starter/helpers/gulp_asset_helper.rb: in join, line 14

我不是肯定Rails和Middleman之間的區別,理解爲什麼這不起作用。

module GulpAssetHelper 
    def gulp_asset_path(path, type = nil) 
    rev_manifest = nil 

    # In development, check for the manifest every time 
    if !config[:build] 
     rev_manifest = JSON.parse(File.read(REV_MANIFEST_PATH)) if File.exist?(REV_MANIFEST_PATH) 
    # In production, use the manifest cached in initializers/gulp.rb 
    else 
     rev_manifest = REV_MANIFEST if defined?(REV_MANIFEST) 
    end 

    root = GULP_CONFIG['root']['dest'].gsub(/(.*)build\//, '/') 
    asset_path = type ? File.join(GULP_CONFIG['tasks'][type]['dest'], path) : path # LINE 14 
    asset_path = rev_manifest[asset_path] if rev_manifest 
    asset_path = File.join(root, asset_path) 
    File.absolute_path(asset_path, '/') 
    end 

    def gulp_js_path(path) 
    gulp_asset_path(path, 'js') 
    GULP_CONFIG 
    end 

    def gulp_css_path(path) 
    gulp_asset_path(path, 'css') 
    end 

    def gulp_image_path(path) 
    gulp_asset_path(path, 'images') 
    end 

    def sprite(id, classes = "", viewBox = "0 0 24 24") 
    "<svg class='sprite -#{id} #{classes}' aria-hidden='true' preserveAspectRatio viewBox='#{viewBox}'><use xlink:href='#{gulp_image_path('sprites.svg')}##{id}' /></use></svg>".html_safe 
    end 
end 

的轉速和配置導入文件:

GULP_CONFIG = JSON.parse(File.read('gulpfile.js/config.json')) 
REV_MANIFEST_PATH = File.join(GULP_CONFIG['root']['dest'], 'rev-manifest.json') 

if File.exist?(REV_MANIFEST_PATH) 
    REV_MANIFEST = JSON.parse(File.read(REV_MANIFEST_PATH)) 
end 

rev-manifest.json文件:

{ 
    "images/middleman-logo.svg": "images/middleman-logo-2e3d8b5ad1.svg", 
    "javascripts/all.js": "javascripts/all-92681c51e741e0e1370c.js", 
    "stylesheets/site.css": "stylesheets/site-9b25f1d1ac.css" 
} 

我已經輸出的gulpfile的內容,以便知道它被正確讀取。

你可以找到完整的回購在這裏:https://github.com/craigmdennis/middleman-gulp-starter/tree/4_asset-helpers

+1

如果在第14行出現錯誤,請爲我們標記第14行。 – Meier

回答

1

它看起來像它失敗在這條線:

asset_path = type ? File.join(GULP_CONFIG['tasks'][type]['dest'], path) : path 

File.join方法期望的字符串因此無論是GULP_CONFIG['tasks'][type]['dest']path不是一個字符串,但一符號。試試這樣:

asset_path = type ? File.join(GULP_CONFIG['tasks'][type.to_s]['dest'].to_s, path.to_s) : path.to_s 
+0

因此,這工作(如沒有更多的錯誤),但似乎只是輸出整個json文件 – Craig

+0

好吧,我錯誤地配置了實際的腳本標記。這工作完美。謝謝。 – Craig