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

**URL:** <https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531>\
**Category:** Rails\
**Created:** [September 15, 2009, 9:12am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531 "2009-09-15T09:12:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 15, 2009, 9:12am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/1 "2009-09-15T09:12:02Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 15, 2009, 9:58am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/2 "2009-09-15T09:58:17Z")

</div>

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](http://twitter.com/abhinav)

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 15, 2009, 10:04am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/3 "2009-09-15T10:04:58Z")

</div>

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

Sijo

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 15, 2009, 5:33pm UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/4 "2009-09-15T17:33:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 16, 2009, 2:21am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/5 "2009-09-16T02:21:55Z")

</div>

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???

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 17, 2009, 3:13am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/6 "2009-09-17T03:13:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 16, 2009, 9:53am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/7 "2009-09-16T09:53:36Z")

</div>

check params[:commit]

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

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [September 17, 2009, 5:11am UTC](https://www.ruby-forum.com/t/2-submit-buttons-how-to-identify-which-pressed-in-the-controller/175531/8 "2009-09-17T05:11:30Z")

</div>

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.
