So, i''m not sure exactly how to do this, or if it is a smart thing to do this. I need some help on the best way to approach this. I have a simple form, it has a text_field and a text_area. I want to add 2 submit buttons. Each one will do a different action. I was thinking I could do form_for, and fields_for, but then I thought that fields_for is used for having two objects, but I only have one. I know I could just make them images, and links, but I suck at photoshop, and my boss is one of those people that feels he is a designer, and he tells me that I have to have some sort of flashing animated gif that is on the right hand side, and some link that has to be red over on the left side. He also told me I have to have two buttons, but I don''t know how to do that. <% form_for(:trouble_ticket, @ticket, :url => { update_url }) do |f| %> <p>Repaired by:<br /> <%= f.text_field(:repair_tech_name) %></p> <p>Comments:<br /> <%= f.text_area(:comments) %></p> <p><%= submit_tag(''Close ticket'') %> or <%= submit_tag(''Assign Ticket'') %></p> <% end %> Thanks, ~Jeremy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is just me, but I''d make them both buttons and assign a javascript function to the onclick events. In the function, I''d grab the form via prototype, set the action accordingly, then submit it. There''s probably a more Rails-pure way of doing it, but I generally go with what works first. Peace, Phillip On Dec 7, 2007, at 1:43 PM, Jeremy Woertink wrote:> > So, i''m not sure exactly how to do this, or if it is a smart thing > to do > this. I need some help on the best way to approach this. > > I have a simple form, it has a text_field and a text_area. I want > to add > 2 submit buttons. Each one will do a different action. I was > thinking I > could do form_for, and fields_for, but then I thought that > fields_for is > used for having two objects, but I only have one. I know I could just > make them images, and links, but I suck at photoshop, and my boss > is one > of those people that feels he is a designer, and he tells me that I > have > to have some sort of flashing animated gif that is on the right hand > side, and some link that has to be red over on the left side. He also > told me I have to have two buttons, but I don''t know how to do that. > > <% form_for(:trouble_ticket, @ticket, :url => { update_url }) do | > f| %> > <p>Repaired by:<br /> > <%= f.text_field(:repair_tech_name) %></p> > <p>Comments:<br /> > <%= f.text_area(:comments) %></p> > <p><%= submit_tag(''Close ticket'') %> or <%= submit_tag(''Assign > Ticket'') %></p> > <% end %> > > Thanks, > > ~Jeremy > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe wrote:> This is just me, but I''d make them both buttons and assign a > javascript function to the onclick events. In the function, I''d grab > the form via prototype, set the action accordingly, then submit it. > There''s probably a more Rails-pure way of doing it, but I generally > go with what works first. > > Peace, > Phillipthat sounds awesome, unfortunately my javascript skills suck, but I will see what I can come up with doing it that way. Thanks for the advice. ~Jeremy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Woertink wrote:> Phillip Koebbe wrote: >> This is just me, but I''d make them both buttons and assign a >> javascript function to the onclick events. In the function, I''d grab >> the form via prototype, set the action accordingly, then submit it. >> There''s probably a more Rails-pure way of doing it, but I generally >> go with what works first. >> >> Peace, >> Phillip > > that sounds awesome, unfortunately my javascript skills suck, but I will > see what I can come up with doing it that way. Thanks for the advice. > > > ~Jeremyhere is a simple javascript call from an onclick: THIS IS A BUTTON IN THE VIEW RHTML FILE: <p><a href="#" onclick="mycoolfunction();">THE BUTTON NAME</a></p> PUT THIS IN THE HEADER SECTION OF THE RHTML <script type=''text/javascript"> function mycoolfuction(){ alert(''I BAD. I BAD. YOU KNOW IT!''); } </script> now, for you easy javascript pleasure, go here, and you will love all this javascript all over the place: http://www.w3schools.com/js/default.asp i did not get into server side junk, and i am not sure you need it. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Jeremy, Sorry to state the obvious here, but there''s only one way for your JS skills to get better...code it. I''ve been writing JS for less than a year, and while I don''t have the knowledge or skills to work on Prototype or Scriptaculous (or any other wonderful library), I can look at it and understand it (for the most part). Heh, I remember the first little JS thing I did. I was "Oh! That''s so cool!" But you have to start somewhere. For this purpose, your code is going to look something like: <input type="button" id="close_button" value="Close Ticket" onclick="close_ticket();" /> <input type="button" id="assign_button" value="Assign Ticket" onclick="assign_ticket();" /> function close_ticket() { var f = $(''ticket_form''); f.action = ''url to closing ticket''; f.submit(); } function assign_ticket() { var f = $(''ticket_form''); f.action = ''url to assigning ticket''; f.submit(); } Assuming you have no special logic for either closing or assigning, you can make this a single function and pass in some value that indicates what you want to do: function submit_form(action) { var = $(''ticket_form''); if (action == ''close'') { f.action = ''url to close''; } else { f.action = ''url to assign''; } f.submit(); } then both buttons would call the same function: <input type="button" id="close_button" value="Close Ticket" onclick="submit_form(''close'');" /> <input type="button" id="assign_button" value="Assign Ticket" onclick="submit_form(''assign'');" /> I haven''t tried this code, so there might be some holes, but the theory is sound. There are also other ways you could change it here and there to make it more compact and dry. I''ll leave that to you. Ahh...after taking from the community for so long, it''s good to finally be able to give something back. Peace, Phillip On Dec 7, 2007, at 5:03 PM, Jeremy Woertink wrote:> > Phillip Koebbe wrote: >> This is just me, but I''d make them both buttons and assign a >> javascript function to the onclick events. In the function, I''d grab >> the form via prototype, set the action accordingly, then submit it. >> There''s probably a more Rails-pure way of doing it, but I generally >> go with what works first. >> >> Peace, >> Phillip > > that sounds awesome, unfortunately my javascript skills suck, but I > will > see what I can come up with doing it that way. Thanks for the advice. > > > ~Jeremy > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---