【问题标题】:Rails make a gem via enginesRails 通过引擎制作宝石
【发布时间】:2016-07-23 15:26:04
【问题描述】:

我想制作一个包含视图助手的 gem。我看这个tutorial, 但我遇到了一些问题。

如果您需要更多信息,这里是github

助手只会打印Hello world!

app/helpers/google_code.rb

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

lib/google_prettify_rails.rb 需要“google_prettify_rails/version”

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

然后,我创建了另一个项目并安装了它,并在视图中输入&lt;%= put_code %&gt;。但是,它抛出了这个错误

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

【问题讨论】:

    标签: ruby-on-rails rubygems rails-engines


    【解决方案1】:

    您的助手名称与助手所在文件的名称不匹配。只需将app/helpers/google_prettify_rails_helper.rb 的第一行更改为GooglePrettifyRailsHelper

    【讨论】:

    • 谢谢,对我很有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多