开发者

Accessing a nested hash in a controller

开发者 https://www.devze.com 2022-12-30 02:36 出处:网络
I have the following (snipped) parameters passed into my controller. Parameters: {\"commit\"=>\"OK\", \"action\"=>\"set_incident_incident_status_id\", \"id\"=>\"1\", \"controller\"=>\"inc

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"=>开发者_如何学JAVA"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!


Small tweak:

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

精彩评论

暂无评论...
验证码 换一张
取 消