When we want to share a form we make a partial of it:

app/views/users/_fields.html.erb

<%= f.label :name %> <br />
<%= f.text_field :name %> <br />

<%= f.label :password %> <br />
<%= f.password_field :password %>


and then we implement the code:

app/views/users/new.html.erb

<%= form_for(@user) do |f| %>
<%= render 'fields', :f => f %>

<%= f.submit "Submit" %>
<% end %>

in the case of a shared error messaging system:

app/views/shared/_error_messages.html.erb

<% if object.errors.any> %>

<%= pluralize(object.errors.count, "error") %> are present. And those
are : <br />
<ul>
<% object.errors.full_messages.each do |msg| %>
<li> <%= msg %> </li>
<% end %>
</ul>

<% end %>

and we pass the render code:

<%= render 'shared/error_messages', :object => f.object %>

inside the form_for helper

My question is why in the case of error_messages partial we pass the
f.object and not just f since f is the object itself
and in the case of field partian (that holds the form) we pass just
f ?

Wouldnt it work if we wrote <%= render 'shared/
error_messages', :object => f %> ?
what is the difference?

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to