You want to set your comment variable in the controller:
def new
@comment = @post.comments.build
end
so your form is
<%= form_for([@post, @comment]) do |f| %>
<%= render"shared/error_messages", :target => @comment %>
<% end %>
If you build the comment in the form (which you shouldn't be doing
anyways if you're sticking to MVC principles), then when you render the
form, a new comment object is always created. Since it's a new object,
it won't have any errors.
--
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.
No comments:
Post a Comment