Ruby/Rails - 访问参数值 [英] Ruby/Rails - Accessing params values

查看:33
本文介绍了Ruby/Rails - 访问参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设一个新手问题,但我们开始了:我有以下参数:

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"}

在我的代码中,我需要将 @tempfile 的值分配给一个局部变量,但我不知道怎么做.;-)

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

推荐答案

大部分参数都在 params 中.所以试试

Most part of params are in params. So try

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

这篇关于Ruby/Rails - 访问参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆