[英]Changing the way params comes in from the form - Rails
Right now I'm using a hidden field tag to get the plan_id. 现在,我正在使用隐藏字段标记来获取plan_id。 But when I use I binding.pry it's nested in the accounts hash. 但是,当我使用我的binding.pry时,它嵌套在帐户哈希中。 In order to get to the plan_id I have to do this params[:accounts][:plan_id]
when I simply want to do this params[:plan_id]
. 为了进入plan_id,我只想执行以下params[:accounts][:plan_id]
时,就必须执行以下params[:plan_id]
。 How can I achieve this? 我该如何实现? Here is my code. 这是我的代码。
<label>
<%= f.hidden_field :plan_id, value: 1 %>
<%= f.submit "Select", class: "button-big reverse-blue" %>
</label>
Here is my params look like 这是我的参数看起来像
{ "account"=>{"name"=>"something", "plan_id"=>"1"}, "stripe_card_token"=>"", "card_number"=>"", "card_holder"=>"", "controller"=>"accounts", "action"=>"create"}
I want them to look like this 我希望他们看起来像这样
{"account"=>{"name"=>"something"}, "plan_id"=>"1", "stripe_card_token"=>"", "card_number"=>"", "card_holder"=>"", "controller"=>"accounts", "action"=>"create"}
Again. 再次。 I'd like to access the plan Id by simply typing this params[:plan_id]
我想通过简单地输入以下params[:plan_id]
来访问计划ID params[:plan_id]
您可以使用hidden_field_tag
<%= hidden_field_tag :plan_id, 1 %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.