When we want to share a form we make a partial of it:
app/views/users/_fields.html.erb
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :password %>
<%= 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 :
-
<% object.errors.full_messages.each do |msg| %>
- <%= msg %> <% end %>
<% 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?