Cameron Bass Cameron Bass - 1 month ago 11
Ruby Question

Pass plan_id into params with submit button

I need to have two submit buttons in one form. The first one also needs to pass plan_id params with it. So basically I need this in my controller params

"plan_id"=>"3"
. Right now my submit button looks like this
<%= f.submit "Select", class: "button-big reverse-blue", name: "plan_id", value: "1" %>
This does not work, if I put a pry in the create action I have no params for plan id. My question is this, how can I pass the plan_id of 1 into the form submit button?

HTML



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

Answer

Why don't you use an hidden field in your form for that? Something like

<%= f.hidden_field :plan_id, value: plan_id %>