I made some custom validations for my app, which do catch invalid data
in the console. However, when I enter invalid data through a form on the
browser view, I get your stack trace error style page (similar to what
you see when you get a syntax error or a nil object) instead of the
nicely styled error messages (what you would see in a scaffolded
application.
First off, what is the stack trace error screen called in rails? And
secondly, why can't I style the error?
I made some custom validations for my app, which do catch invalid data
in the console. However, when I enter invalid data through a form on the
browser view, I get your stack trace error style page (similar to what
you see when you get a syntax error or a nil object) instead of the
nicely styled error messages (what you would see in a scaffolded
application.
First off, what is the stack trace error screen called in rails? And
secondly, why can't I style the error?
Can you provide an example of what you mean? If you are getting a
runtime Ruby error then you should never allow that to happen in your
code, so there is no need to style it. If for example a variable may
be nil then you must test for nil before using it. Perhaps I
misunderstand what you mean however.
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
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.