where to find documentation on how to develop (rails 3) helpers [closed]

我的梦境 提交于 2019-12-10 18:24:55

问题


I may be blind but I can't really find any good documentation on how to write helpers for your own views in rails 3. The kind of answers I'm looking for is:

I have a partial view (say shared/_error_messages.html), where should its helper go, how should I name it, which are the conventions? How to pass local variables from the view to the helper and vice-versa?

Yeap, so let's say from the basics... Thanks in advance


回答1:


Extract the method from _error_messages.html.erb to helpers/application_helper.html.erb, this is a global helper, which means the methods there are available in the whole project.

You could leave it as a partial and load it with

<%= render :partial => "shared/error_messages" %> 

as well.



来源:https://stackoverflow.com/questions/4265389/where-to-find-documentation-on-how-to-develop-rails-3-helpers

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