2 submit buttons, how to identify which pressed in the controller?

Hi

I have the following code:
<%= f.submit ‘First’, :class => “mybutton”, :myid=> “xx” %>
<%= f.submit ‘Second’ %>

I would have expected to use params[:myid] to check which submit
button was pressed but it does not seem to register the params value.

Or is it just not possible to check which submission button was
pressed?

Thanks!

Although I have never used two form submits in a single form, but
perhaps
you can use “value” to pass id instead of using params.

Thanks,
Abhinav

अभिनव
http://twitter.com/abhinav

Hi
You can check params[:commit] In first case its value is ‘First’
and in second it is ‘Second’

Sijo

Sijo Kg wrote:

Hi
You can check params[:commit] In first case its value is ‘First’
and in second it is ‘Second’

Here’s a hint: Submit a form and look at the development.log. You can
see clearly what was sent in the params hash. Incidentally this works
for any request sent to your Rails app.

Robert W. wrote:

Here’s a hint: Submit a form and look at the development.log. You can
see clearly what was sent in the params hash. Incidentally this works
for any request sent to your Rails app.

There you go again, teaching people how to fish…

Pretty soon they will all be reading the framework documentation,
adopting an inquisitive nature, performing their own experiments, and
not coming here to post their questions for all of us to answer, while
we really should be doing the work we get paid for…

Are you trying to turn this forum into a wasteland, filled with only the
most esoteric and diabolical of questions???

Thank you all for your reply. The best was of course to check my
console as I knew my variables were there before, no clue why I forgot
about this.

I am not scared to ask another question; I use a form_for to output
the data fields of a class to the user, I receive this back as a
param. What is the best way to use this param again as output to data
fields to the user without actually saving the class?
I have tried using new/clone but it looks all pretty hacky. The nicest
solution would be to extract all variables out of the class and handle
them separately but thats quite some code and so far rails has shown
that more duplicate code is mostly incorrect.

check params[:commit]

if params[:commit] == ‘first’
else params[:commit] == ‘second’
end

If you have built your form from an instance variable you can get the
screen values back into an object with:

@my_object = MyClass.new(params[:my_object])

Then render the view and you should be done.