Matt
2009-Sep-15 07:10 UTC
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!
Abhinav Saxena
2009-Sep-15 07:56 UTC
Re: 2 submit buttons, how to identify which pressed in the controller?
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 On Tue, Sep 15, 2009 at 12:40 PM, Matt <mattbogers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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! > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sijo Kg
2009-Sep-15 08:04 UTC
Re: 2 submit buttons, how to identify which pressed in the controller?
Hi You can check params[:commit] In first case its value is ''First'' and in second it is ''Second'' Sijo -- Posted via http://www.ruby-forum.com/.
Robert Walker
2009-Sep-15 15:33 UTC
Re: 2 submit buttons, how to identify which pressed in the
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. -- Posted via http://www.ruby-forum.com/.
Robert Walker 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??? -- Posted via http://www.ruby-forum.com/.
sam
2009-Sep-16 01:11 UTC
Re: 2 submit buttons, how to identify which pressed in the controller?
check params[:commit] if params[:commit] == ''first'' else params[:commit] == ''second'' end On Sep 15, 1:10 am, Matt <mattbog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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!
Matt
2009-Sep-17 01:10 UTC
Re: 2 submit buttons, how to identify which pressed in the controller?
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.
pepe
2009-Sep-17 03:02 UTC
Re: 2 submit buttons, how to identify which pressed in the controller?
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. On Sep 16, 9:10 pm, Matt <mattbog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.