Sergio Tapia
2012-Feb-05 16:23 UTC
How do I create a Rails action for an Ajax request? Rails 3.2.1
I have a list of items in my shopping page, and each time an "add to cart" button is clicked, an AJAX request is fired off with only a product_id. "Add this item to the cart" so to speak. What does my Action have to look like in Rails for this scenario? I''m specifically asking about the controller side, and what the action would look like. Just assume it receives a numerical ID. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Valery Kvon
2012-Feb-05 20:55 UTC
Re: How do I create a Rails action for an Ajax request? Rails 3.2.1
On 05.02.2012, at 20:23, Sergio Tapia wrote:> I have a list of items in my shopping page, and each time an "add to > cart" button is clicked, an AJAX request is fired off with only a > product_id. > > "Add this item to the cart" so to speak. > > What does my Action have to look like in Rails for this scenario? >def action_name respond_to do |format| format.js do ... end end end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sergio Tapia
2012-Feb-05 22:07 UTC
Re: How do I create a Rails action for an Ajax request? Rails 3.2.1
Jesus it''s that simple? I''ll come back with my results! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Feb-05 22:17 UTC
Re: Re: How do I create a Rails action for an Ajax request? Rails 3.2.1
On 5 February 2012 22:07, Sergio Tapia <sergiotapiagutierrez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Jesus it''s that simple? I''ll come back with my results!Of course you have also got to do whatever it is that you actually want to achieve - finding the appropriate record or whatever. Coin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.