passing values to partial in rails 3

随声附和 提交于 2019-11-30 05:03:51

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')

Try this:

Main page:

<%= render :partial => 'layouts/test',
           :locals => {:text_1 => t(:'text_1'), :text_2 => t(:'text_2')}
%>

Partial:

<%= text_1 %> <%= text_2 %>
Andrew K

I believe that Rails 3 has changed how you pass partial variables, to something like this:

<%= render :partial => 'layouts/test',
       :text_1 => t(:'text_1'), :text_2 => t(:'text_2') %>

Rails will parse that and since :text_1 is not a known key (like :collection or :as), it passes it to the partial itself.

You can access it via text_1 or text_2

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