Hello, I am having a problem in using AJAX in Rails(I am trying for the first time), and I am pretty sure it is because of routing. This is my code http://pastie.org/412541 As far I knew the URL''s were supposed to be like "/controller/action/ id" but when I do "/controller/action" it throws an error "Could not find model with ID=action" and that is why my AJAX calls aren''t working. I do not wish to use form_for_remote or link_to_remote as I need to make these calls from JS. Could someone please help me out. Regards, Prateek --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
you should read up on REST. maybe start here: http://railscasts.com/episodes/35-custom-rest-actions --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-10 07:09 UTC
Re: Routing and AJAX problem.
On 10 Mar., 07:49, Prateek <prtks...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I am having a problem in using AJAX in Rails(I am trying for the first > time), and I am pretty sure it is because of routing. This is my codehttp://pastie.org/412541 > > As far I knew the URL''s were supposed to be like "/controller/action/ > id" but when I do "/controller/action" it throws an error "Could not > find model with ID=action" and that is why my AJAX calls aren''t > working. I do not wish to use form_for_remote or link_to_remote as I > need to make these calls from JS. > > Could someone please help me out.When you''re using RESTful routes (map.resources) you should not request /projects/create.json but /projects.json. I would simply change your code into this: http://pastie.org/412548. Two changes have been made: I''ve changed "/projects/create.json? authenticity_token=0000&project[title]=lala" into "/projects.json? project[title]=lala" and added a line saying "protect_from_forgery :except => :create" in the ProjectsController. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks a lot. Working now. @MaD - Thanks for the link --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---