2016-07-23 68 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

谢谢,这对我来说真的很有用。 –