2016-07-23 67 views
0

我想製作一個包含視圖助手的寶石。我看這tutorial, 但我遇到一些問題。Rails通過引擎製作寶石

這裏是github,如果您需要更多信息。

該幫手只打印Hello world!

應用程序/傭工/ google_code.rb

module GoogleCode 
    def self.put_code 
     content_tag(:p, "Hello world!") 
    end 
end 

的lib/google_prettify_rails.rb 要求 「google_prettify_rails /版」

module GooglePrettifyRails 
    class Engine < ::Rails::Engine 
    end 
end 

然後,我創造了另一個項目,並安裝它,並輸入<%= put_code %>。然而,它拋出了這個錯誤

Couldn't find GooglePrettifyRailsHelper, expected it to be defined in helpers/google_prettify_rails_helper.rb 

回答

2

你的助手的名字和助手所在的文件的名稱不匹配。只需將第一行app/helpers/google_prettify_rails_helper.rb更改爲GooglePrettifyRailsHelper即可。

+0

謝謝,這對我來說真的很有用。 –