开发者

The scope of custom helper

开发者 https://www.devze.com 2023-02-06 09:50 出处:网络
I have defined my helper function in Helper: module CarsHelper def my_helper ... end end But I can neither used it(my_helper) in my CarsController nor in Car model, is it so t开发者_JAVA百科hat t

I have defined my helper function in Helper:

module CarsHelper

  def my_helper
    ...
  end

end

But I can neither used it(my_helper) in my CarsController nor in Car model, is it so t开发者_JAVA百科hat the custom helper can only be used in View?


Helpers are normally for views. But you can include them in your controllers as well. Just add

helper :cars

to your controller. (docs)

Models are out of scope for helpers. Use class or instance methods in there instead.


The new way to use view helpers in controllers is to use: helpers.[helpername]

See this for more.

0

精彩评论

暂无评论...
验证码 换一张
取 消