Check if error_messages_for is set

How do I check if error_messages_for is set?

error_messages_for is a method, I assume what you meant to ask was how to check whether there are any errors. You can either call valid? or look at your_ar_object.errors

Fred

Look at the error carefully, if it is finding nil. then maybe either params is nil (unlikely unless you typed it incorrectly) or params[:company] is nil. Look in the log file (in your application log folder) it will show you the parameters posted.

Colin

Frederick Cheung wrote:

Hmm. Ok. How do I check if a params part of the model is set? If run:

if params[:kind]

That doesn't check the model at all, you're just looking at the submitted parameters. Or am I misunderstanding the question

it's ok. But when I test with

if params[:company][:kind]

it returns "The error occurred while evaluating nil."

if the parameters may or may not be there you need to check whether params[:company] exists before you can look at params[:company][:kind]

Fred

Pål Bergström wrote:

What a long way for a simple answer, that I knew before. Why on earth check error_messages_for when I have params[my_model] :slight_smile:

Thanks for the help.