Bitwise
Bitwise

Reputation: 8461

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 params[:accounts][:plan_id] when I simply want to do this 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]

Upvotes: 1

Views: 19

Answers (1)

Ursus
Ursus

Reputation: 30056

You could use hidden_field_tag

<%= hidden_field_tag :plan_id, 1 %>

Upvotes: 2

Related Questions