[Rails] removing instance variables in partials?
Hi,
I read some articles about why partials should not have instance
variables in them. But in "Ruby on Rails 3 Tutorial" the author starts
with this partial:
View:
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
Partial:
<% if @users.errors.any? %>
...
...
I thought removing the @user instance variable from the partial would
have involved doing this:
View:
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :user => @user %>
Partial:
<% if user.errors.any? %>
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?
--
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