Calling helper method from Rails 3 controller

不问归期 提交于 2019-11-28 22:40:03
 view_context.some_helper_method

You can either include the helper module in the controller, or define the helper as a controller method and mark it as a helper via helper_method :method_name.

class FooHelper
  def bar ... end
end

class QuxsController
  include FooHelper
end

or

class QuxsController
  private
  def bar ... end
  helper_method :bar
end

This is working if some one wants to use ApplicationHelper method in other controllers or view just add this include ApplicationHelper give below because all your controller derived from ApplicationController.

class ApplicationController < ActionController::Base
  protect_from_forgery       
  include ApplicationHelper  
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!