Fred,
Thanks for the recommendation. I added the code below to my comments
controller:
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(params[:comment])
respond_to do |format|
if @comment.create(params[:comment])
format.html { redirect_to(@post) }
format.xml { render :xml => @post, :status => :created,
:location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status =>
:unprocessable_entity }
end
end
end
I'm still not getting the errors to show up in red on the form. This is
a comment form within the post "show" view, which might be different?
The errors show in red when I'm creating a new game, but I get the
runtime error when making a new invalid comment.
Thanks!
Frederick Cheung wrote:
> On Sep 1, 12:48�pm, Ze Ca <li...@ruby-forum.com> wrote:
>> style it in a way that gives off a red warning directly on the page.
>>
>
> typically you do something like
>
> if Foo.create(params[...])
> #handle success
> else
> render ... #re render the form used to submit the object
> end
>
> If you do this the object that failed validation is still around, so
> you can prefill edit fields and so on with what the user has just
> tried and either display the errors yourself or use
> error_messages_for / f.error_messages
>
> Fred
--
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