3

在我的 gemfile 中,我有gem 'stringex'. 运行后bundle install,我添加了一个路径助手,并使用了来自 stringex 的方法。我应该能够to_url直接在字符串上使用,就像 stringex 自述文件中的示例:"simple English".to_url => "simple-english"

但是,当我尝试在路径助手中的字符串上使用方法 .to_url 时,我得到:

undefined method 'to_url' for "fake title":String

我的辅助方法看起来像:

module PostsHelper
  def post_path(post)
      "/posts/#{post.id}/#{post.title.to_url}"
  end
end
4

2 回答 2

1

您可以尝试的一件事是运行bundle exec irb,然后尝试require "stringex". 如果您不能正确地要求 gem,那么它就没有安装在包中。

于 2012-05-12T19:07:09.587 回答
0

您将需要添加require 'stringex'到文件的顶部posts_helper.rb

于 2017-08-10T18:31:35.233 回答