Check if error_messages_for is set

How do I check if error_messages_for is set?

On Aug 17, 7:31 pm, Pål Bergström [email protected]
wrote:

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

Frederick C. wrote:

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

if params[:kind]

it’s ok. But when I test with

if params[:company][:kind]

it returns “The error occurred while evaluating nil.[]”

On Aug 17, 9:04 pm, Pål Bergström [email protected]
wrote:

Frederick C. 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

2009/8/17 PÃ¥l Bergström [email protected]:

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

if params[:kind]

it’s ok. But when I test with

if params[:company][:kind]

it returns “The error occurred while evaluating nil.[]”

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

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.

Frederick C. wrote:

On Aug 17, 9:04�pm, P�l Bergstr�m [email protected]
wrote:

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

It’s a submitted parameters. :slight_smile:

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]

Thanks. That might be it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs