# Routing and AJAX problem

**URL:** <https://www.ruby-forum.com/t/routing-and-ajax-problem/162471>\
**Category:** Rails\
**Created:** [March 10, 2009, 7:50am UTC](https://www.ruby-forum.com/t/routing-and-ajax-problem/162471 "2009-03-10T07:50:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prateek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@Prateek](https://www.ruby-forum.com/u/Prateek)\
**Post date:** [March 10, 2009, 7:50am UTC](https://www.ruby-forum.com/t/routing-and-ajax-problem/162471/1 "2009-03-10T07:50:06Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Prateek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@Prateek](https://www.ruby-forum.com/u/Prateek)\
**Post date:** [March 10, 2009, 8:00am UTC](https://www.ruby-forum.com/t/routing-and-ajax-problem/162471/2 "2009-03-10T08:00:02Z")

</div>

you should read up on REST. maybe start here:

> **[\#35 Custom REST Actions - RailsCasts](http://railscasts.com/episodes/35-custom-rest-actions)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

---

<div class="post-metadata">

**Author:** ![Prateek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@Prateek](https://www.ruby-forum.com/u/Prateek)\
**Post date:** [March 10, 2009, 8:09am UTC](https://www.ruby-forum.com/t/routing-and-ajax-problem/162471/3 "2009-03-10T08:09:59Z")

</div>

On 10 Mar., 07:49, Prateek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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](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 K.  
[http://twitter.com/rubyguy](http://twitter.com/rubyguy)

---

<div class="post-metadata">

**Author:** ![Prateek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@Prateek](https://www.ruby-forum.com/u/Prateek)\
**Post date:** [March 13, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/routing-and-ajax-problem/162471/4 "2009-03-13T12:50:48Z")

</div>

Thanks a lot. Working now.  
@MaD - Thanks for the link
