将值传递给 rails 3 中的部分 [英] passing values to partial in rails 3
本文介绍了将值传递给 rails 3 中的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我将值/变量传递给部分的方式:
Here is how I pass the values/variable to the partial:
<%= render "partials/banner", :locals => {:text_1 => t(:"main.home.banner_text_1"),
:text_2 => t(:"main.home.banner_text_2") } %>
然后在部分:
<%= text_1 %> <%= text_2 %>
但得到未定义的局部变量或方法 text_1"
but getting "undefined local variable or method text_1"
我应该在哪里设置变量,以便它可以从我应用中的所有视图和布局访问?
Where should I set the variable so it could be accesible from all views and layouts in my app?
谢谢!
推荐答案
如果您需要在所有视图中显示某些内容,您还可以创建一个 application_helper 方法,例如:banner('Text', '内容')
If you have something that has to be displayed across all your views you can also create a application_helper method, Example: banner('Text', 'Content')
试试这个:
主页:
<%= render :partial => 'layouts/test',
:locals => {:text_1 => t(:'text_1'), :text_2 => t(:'text_2')}
%>
部分:
<%= text_1 %> <%= text_2 %>
这篇关于将值传递给 rails 3 中的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文