在哪里可以找到有关如何开发(rails 3)帮助器的文档 [英] where to find documentation on how to develop (rails 3) helpers

查看:121
本文介绍了在哪里可以找到有关如何开发(rails 3)帮助器的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能是盲人的,但我找不到任何关于如何在rails 3中为自己的意见编写帮助者的好的文档。
我正在寻找的答案是:



我有一个局部视图(说shared / _error_messages.html),它的帮助应该在哪里去,我该怎么命名,哪些约定?
如何将局部变量从视图传递给助手,反之亦然?



是的,我们从基础知道...
提前感谢

解决方案

将方法从_error_messages.html.erb提取为helpers / application_helper.html.erb,这是一个全局帮助者,这意味着整个项目中可用的方法。



您可以将其作为部分留下,并将其加载到

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


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

解决方案

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.

这篇关于在哪里可以找到有关如何开发(rails 3)帮助器的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆