0

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. ;-)

Thomas
  • 622
  • 5
  • 13

2 Answers2

1

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
shivam
  • 16,048
  • 3
  • 56
  • 71
1

Most part of params are in params. So try

local_val = params["import"]["csv"].tempfile
shirakia
  • 2,369
  • 1
  • 22
  • 33
  • Just what I was looking for. Thank yo and also thank you to @shivam. I will accept your answer as it it more clean. – Thomas Dec 11 '14 at 10:46