[Rails] Re: removing instance variables in partials?
7stud -- wrote in post #1014561:
> But the author actually does this:
>
> View:
> <%= form_for(@user) do |f| %>
> <%= render 'shared/error_messages', :object => f.object %>
>
> Partial:
> <% if object.errors.any? %>
>
>
> The author says that f.object is "the object corresponding to the form
> variable f". Is that right? What's f then? Based on the way f.object
> is used, it appears to be equivalent to @user. Is it?
The variable f is a reference to the FormBuilder object, which in turn
holds a reference to the object assigned to it (form_for @user) so
f.object would be a reference to @user. The use of :object => f.object
would ensure that the object passed into the partial is truly the object
referenced by the FormBuilder f.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home