Ruby / Rails – 访问params值

我假设一个新手问题但是我们走了:我有以下参数:

{"utf8"=>"✓", authenticity_token"=>".........", "import"=> {"csv"=> #<ActionDispatch::Http::UploadedFile:0x007fb59092a660 @content_type="text/csv", @headers="Content-Disposition: form-data; name=\"import[csv]\"; filename=\"Users.csv\"\r\nContent-Type: text/csv\r\n", @original_filename="DemoUsers.csv", @tempfile=#>, "datatype"=>"users"}, "commit"=>"Import", "action"=>"create", "controller"=>"imports"} 

在我的代码中,我需要将@tempfile的值@tempfile局部变量,但我无法弄清楚如何。 😉

参数的大部分都在params 。 所以试试吧

 local_val = params["import"]["csv"].tempfile 

假设您为变量res分配响应

 res = {"utf8"=>"✓", authenticity_token"=>".........", "import"=> {"csv"=> #>, "datatype"=>"users"}, "commit"=>"Import", "action"=>"create", "controller"=>"imports"} 

现在,

 res["import"]["csv"].tempfile