Thomas
Thomas

Reputation: 622

Ruby/Rails - Accessing params values

A newbie question I assume but here we go: I have the following 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=#<File:/var/folders/_p/w29hlx3x0cs6h026txv_rqhc0000gn/T/RackMultipart20141211-8204-1ha0i1u>>,
   "datatype"=>"users"},
 "commit"=>"Import",
 "action"=>"create",
 "controller"=>"imports"}

In my code, I need to assigns the value of @tempfile to a local variable but I just cant figure out how. ;-)

Upvotes: 0

Views: 143

Answers (2)

shirakia
shirakia

Reputation: 2409

Most part of params are in params. So try

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

Upvotes: 1

shivam
shivam

Reputation: 16506

suppose you assign response to a variable res

res = {"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=#<File:/var/folders/_p/w29hlx3x0cs6h026txv_rqhc0000gn/T/RackMultipart20141211-8204-1ha0i1u>>,
   "datatype"=>"users"},
 "commit"=>"Import",
 "action"=>"create",
 "controller"=>"imports"}

Now,

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

Upvotes: 1

Related Questions