undefined method 'link_to'

你离开我真会死。 提交于 2019-12-03 10:01:46

This is because, ActionView urlhelpers are only available to the Views, not in your lib directory.

the link_to method is found in the ActionView::Helpers::UrlHelper module, plus you wou

so try this.

 class Facet
   include ActionView::Helpers::UrlHelper
...
end

Try this:

ActionController::Base.helpers.link_to

Simply including the helper doesn't get you much further. The helpers assume that they are in the context of a request, so that they can read out the domain name and so on.

Do it the other way around; include your modules in the application helper, or something like that.

# lib/my_custom_helper.rb
module MyCustomHelper
  def do_stuff
    # use link_to and so on
  end
end

# app/helpers/application_helper.rb
module ApplicationHelper
  include MyCustomHelper
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!