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?