0

I have been trying to pass what round the users intends to go to by which button they click through a hidden field that passes in the round number.

<%= form_for @round, :url => { :action => 'pick_page'} do |f| %>

<%= f.hidden_field :round, :value => '1', :class =>'round1' %>
<%= f.submit 'Picks', :class => 'round1' %>

<%= f.hidden_field :round, :value => '2', :class =>'round2' %>
<%= f.submit 'Picks', :class => 'round2' %>

<% end %>

With this code I constantly get 2 passed through as the round in my pick_page. It is obviously skipping over the first hidden field. How can I get it so 'f.submit' submits the round number that is associated with its class.

1
  • You should use 2 different forms I think Commented Nov 13, 2012 at 21:12

2 Answers 2

1

We just had the same problem! We fixed it creating 2 diferent forms right next to each other.

<%= form_for @round, :url => { :action => 'pick_page'} do |f| %>

<%= f.hidden_field :round, :value => '1', :class =>'round1' %>
<%= f.submit 'Picks', :class => 'round1' %>

<%= f.hidden_field :round, :value => '2', :class =>'round2' %>
<%= f.submit 'Picks', :class => 'round2' %>

<% end %>

Change it to

<%= form_for @round, :url => { :action => 'pick_page'} do |f| %>

<%= f.hidden_field :round, :value => '1', :class =>'round1' %>
<%= f.submit 'Picks', :class => 'round1' %>

<% end %>

<%= form_for @round, :url => { :action => 'pick_page'} do |f| %>

<%= f.hidden_field :round, :value => '2', :class =>'round2' %>
<%= f.submit 'Picks', :class => 'round2' %>

<% end %>
Sign up to request clarification or add additional context in comments.

Comments

0

You can just remove the hidden fields and add a name and value attributes on your submit button.

2 Comments

adding a value field like :value => '1' makes the name of the button '1'
Sorry, did not think of that. Then you can give them different name, not use value, and check if a params of this name is sent ? I do not see other solution without using JS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.