Cameron Bass Cameron Bass - 1 year ago 60
Ruby Question

Changing the way params comes in from the form - Rails

Right now I'm using a hidden field tag to get the plan_id. But when I use I binding.pry it's nested in the accounts hash. In order to get to the plan_id I have to do this

when I simply want to do this
. How can I achieve this? Here is my code.

<%= f.hidden_field :plan_id, value: 1 %>
<%= f.submit "Select", class: "button-big reverse-blue" %>

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

Answer Source

You could use hidden_field_tag

<%= hidden_field_tag :plan_id, 1 %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download