Drew Harris
Drew Harris

Reputation: 486

Ruby on rails - read and evaluate params hash

I have a Params hash coming from a form submit that looks like:

{"utf8"=>"✓", "authenticity_token"=>"xxxxxx", "animal"=>{"animal_ids"=>["", "14", "9"], "thisaction"=>"register"}, "controller"=>"animals", "action"=>"takeaction"}

When submitted to "takeaction" I want to evaluate the value of "thisaction" within the hash and what I have is not working. This is what I have in a test view to see what I have:

<p>thisaction: <%= params[:thisaction] %></p>

This always just shows me: thisaction:

No value.

What silly thing am I missing that I need to change to properly evaluate the value of "thisaction"?

Upvotes: 2

Views: 173

Answers (1)

Paul Richter
Paul Richter

Reputation: 11082

It is because the :thisaction key is not located in the root of the parameter map like you're expecting, it is in a "subhash" called :animal. So you will need to access it like so:

params[:animal][:thisaction]

Upvotes: 3

Related Questions