Mauro
(Mauro)
December 25, 2010, 10:54pm
1
I have:
<%= form_for(@supplier ) do |f| %>
.......
......
<%= render 'sector_categories', :locals => {:f => f} %>
in _sector_categories partial I have:
<div class="field">
<div id="category_update">
<% for category in @categories %>
<%= f.check_box :category_ids , category.id,
@supplier.categories.include ?(category) %>
<%= category.name %><br />
<% end %>
</div>
</div>
Why it says: undefined local variable or method "f"?
Jeffrey
(Jeffrey)
December 25, 2010, 11:35pm
2
Quoting Mauro <mrsanna1@gmail.com>:
I have:
<%= form_for(@supplier ) do |f| %>
.......
......
<%= render 'sector_categories', :locals => {:f => f} %>
in _sector_categories partial I have:
<div class="field">
<div id="category_update">
<% for category in @categories %>
<%= f.check_box :category_ids , category.id,
@supplier.categories.include ?(category) %>
<%= category.name %><br />
<% end %>
</div>
</div>
Why it says: undefined local variable or method "f"?
As written, you are rendering a template, not a partial. Passing local
variables to templates is not supported. Do you mean
<%= render :partial => 'sector_categories', :locals => {:f => f} %>
HTH,
Jeffrey
Mauro
(Mauro)
December 25, 2010, 11:42pm
3
But if I create a new application using scaffold I see a code like
this: <%= render 'form' %> and a file _form.html.rb.
So it is a partial but the render command doesn't have :partial.
What's correct?
Mauro
(Mauro)
December 25, 2010, 11:52pm
4
Jeffrey
(Jeffrey)
December 26, 2010, 3:16am
5
Quoting Mauro <mrsanna1@gmail.com>:
Jeffrey
(Jeffrey)
December 26, 2010, 4:20am
6
Quoting Mauro <mrsanna1@gmail.com>:
> Quoting Mauro <mrsanna1@gmail.com>:
>> I have:
>> <%= form_for(@supplier ) do |f| %>
>> .......
>> ......
>> <%= render 'sector_categories', :locals => {:f => f} %>
>>
>> in _sector_categories partial I have:
>>
>> <div class="field">
>> <div id="category_update">
>> <% for category in @categories %>
>> <%= f.check_box :category_ids , category.id,
>> @supplier.categories.include ?(category) %>
>> <%= category.name %><br />
>> <% end %>
>> </div>
>> </div>
>>
>> Why it says: undefined local variable or method "f"?
>>
>
> As written, you are rendering a template, not a partial. Passing local
> variables to templates is not supported. Do you mean
>
> <%= render :partial => 'sector_categories', :locals => {:f => f} %>
As you see in Layouts and Rendering in Rails — Ruby on Rails Guides
there is no need to specify :partial.
Look again. Every example on that page with :locals, explicitly specifies
:partial.
Your way isn't working. How about trying something different. The only way
you will find out if the Rails 2 convention, locals only for partials, is or
isn't true in Rails 3 is trying it. You have shown that without :partial and
possibly some other factor, locals don't work. Change only one thing and run
the experiment again.
Jeffrey
Mauro
(Mauro)
December 26, 2010, 12:12pm
7
You are right, so I've have notice that with rails 3 there is no need
to specify :partial unless I use local variables.