I am working on basic blog engine and i have applied validations on comments but when i do a submit it doesn’t show errors, instead it shows ActiveRecord::RecordInvalid by rails which is default.
my comments controller is
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(params[:comment])
redirect_to @post
end
my posts/show view is as below which is working fine for commenting
<%= form_for [@post, Comment.new] do |f| %>
<p class="comment-notes">Your email address will not be published. Required fields are marked <span class="required">*</span></p>
<p>
<b><%= f.label :name, "Name * " %></b><%= f.text_field :name %><br /></p>
<p>
<b><%= f.label :body, "Comment" %></b><%= f.text_area :comment, :cols => 60, :rows => 5 %>
</p>
<p>
<%= f.submit "Post Comment" %>
</p>
can anybody help me to show validation errors on the same posts/show view?
thanks in advance
replace
with
unlike create, create! will raise error if validations fail
in posts/show