Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing values to partial in 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") } %>

then in the partial:

 <%= text_1 %> <%= text_2 %>

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?

Thanks!

like image 416
bogumbiker Avatar asked Jul 11 '10 09:07

bogumbiker


1 Answers

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 %>
like image 108
Warren Noronha Avatar answered Sep 20 '22 06:09

Warren Noronha