0

我正在提交一个表单来创建我的 SpecialDeal 模型的新记录。提交的参数如下所示:

@_params    
{"utf8"=>"✓", "authenticity_token"=>"cl1SwnHOum8d/kiGnwkDsamG5IMbmdnoeFvlY11KpKc=", "special_deal"=>{"title"=>"5", "provider"=>"5", "description"=>"5", "deal_price"=>"", "conditions"=>"", "expires"=>"07/18/2013 14:38:18", "excerpt"=>"", "original_price"=>"", "phone_number"=>"", "street"=>"", "city"=>"", "postal_code"=>"", "state"=>"", "country"=>""}, "commit"=>"Create Special deal", "action"=>"create", "controller"=>"special_deals"}

然而,当我尝试从expires参数中创建一个变量时......

def create
  expiration = params[:expires]

该变量总是将自己设置为 nil!

Local Variables

expiration: nil

为什么会这样?

4

2 回答 2

3

expires 在“special_deal”键下的内部哈希中,所以试试

def create
  expiration = params[:special_deal][:expires]

我假设您正在使用 rails 参数

于 2013-07-05T12:49:28.460 回答
2

正如我之前评论的那样。现在将其添加为我的答案;)

def create
  expiration = params["special_deal"]["expires"]
  # Your code goes here
end
于 2013-07-05T13:01:30.453 回答