views:

52

answers:

3

I don't seem to be able to pass a variable to my partial template in rails (2.3.5). My code is as follows;

In the main view .html.erb file:

<% f.fields_for :payments do |payment_form| %>
    <%= render 'payment', {:f => payment_form, :t => "test" } %>
<% end %>

and in the _payment.html.erb file:

<%= t %>

produces a wrong number of arguments (0 for 1) error. The payment_form object is being passed to the partial as f without any problems. I've tried a number of variations on the above syntax (e.g. :locals => {:f => payment_form, :t => "test" } without success. I presume I'm doing something pretty basic wrong but just can't see it.

+1  A: 

Try

render :partial => 'payment', :locals => {:t => 'test'}
Evgeny Shadchnev
Nope, doesn't work. The :partial => 'payment' is just a long way of saying 'payment' (as of Rails 2.3) and the :locals hash is missing the :f => payment_form. Thanks for looking at my question though.
brad
+2  A: 

Have you tried <%= render 'payment', :f => payment_form %>

I'm not sure what the :t is for, but rails is obviously saying that you should only be passing in one extra parameter with the wrong number of arguments (0 for 1) error.

mpd
The t was just a way of testing the expression before I passed through the actual variable I wanted (which I hadn't fully created yet). The actual solution is described in the comments of the question thanks to Vlad Romascanu making me look a little closer. There was, in fact, nothing wrong with my expression, I was just calling the partial elsewhere without realising it.
brad
+1  A: 

It's probably because t() is a reserved view helper method used for I18n. Just rename it to something more descriptive

simianarmy
Nope, it didn't matter what I called it, it still didn't work.
brad