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?

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.

Thats what I figured. Thanks.