Magicked
Magicked

Reputation: 647

Accessing a nested hash in a controller

I have the following (snipped) parameters passed into my controller.

Parameters: {"commit"=>"OK", "action"=>"set_incident_incident_status_id", "id"=>"1", "controller"=>"incidents", "incident"=>{"incident_status_id"=>"1"}}

I know that if I want to select the incident, I can do:

@incident = Incident.find(params[:id])

How do I access the "incident"=>{"incident_status_id"=>"1"}?

I thought to try something like:

@incident_status = IncidentStatus.find(params[:incident => :incident_status_id])

But that didn't work. I'm assuming it's just a syntax problem at this point, and I haven't found a solution yet. Any help would be much appreciated!

Upvotes: 0

Views: 464

Answers (1)

user65663
user65663

Reputation:

Small tweak:

@incident_status = IncidentStatus.find(params[:incident][:incident_status_id])

Upvotes: 1

Related Questions