Lalala Liliil
2007-Apr-22 10:06 UTC
called javascript method and ruby method with 1 button?
Hi I create a javascript method in rhtml with <script> function js() </script> and I would like to have 1 button that will call my controller method and js() at the same time, so user will only need to click 1 button instead of 2 Is this possible to do? Thank you -- 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 -~----------~----~----~----~------~----~------~--~---
MichaelLatta
2007-Apr-22 15:30 UTC
Re: called javascript method and ruby method with 1 button?
You can use the link_to_function helper to setup the call to JS or just use straight js to do that. Inside your js function use Ajax.Request or one of its subclasses to call the controller action using XmlHttpRequest. Michael On Apr 22, 3:06 am, Lalala Liliil <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > > I create a javascript method in rhtml with <script> function js() > </script> > and I would like to have 1 button that will call my controller method > and js() at the same time, so user will only need to click 1 button > instead of 2 > > Is this possible to do? > > Thank you > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Chris Mear
2007-Apr-28 11:24 UTC
Re: called javascript method and ruby method with 1 button?
You can use button_to_function with remote_function to create a button that will use Ajax to call an action in your controller. The method remote_function takes the same parameters as link_to_remote, which means that you can then use parameters like :before, :after, :complete, etc. to call arbitrary JavaScript at various points during the Ajax request. For example: <%= button_to_function("Click me", remote_function(:url => {:action => :do_stuff}, :before => "myJavaScriptFunction()")) %> Chris On Apr 22, 11:06 am, Lalala Liliil <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > > I create a javascript method in rhtml with <script> function js() > </script> > and I would like to have 1 button that will call my controller method > and js() at the same time, so user will only need to click 1 button > instead of 2 > > Is this possible to do? > > Thank you > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---