开发者

The scope of custom helper

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜