# nested ressource path problem

**URL:** <https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064>\
**Category:** rubyonrails-talk\
**Created:** [July 19, 2008, 2:47am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064 "2008-07-19T02:47:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parity](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parity](https://discuss.rubyonrails.org/u/Parity)\
**Post date:** [July 19, 2008, 2:47am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/1 "2008-07-19T02:47:13Z")

</div>

Hello :-),

I've started to figure out how nested ressources are working, but I get an exception in a (i think so) simple case. The exception is: "ActionController::MethodNotAllowed - Only get, put, and delete requests are allowed."

webrick tells me: 127.0.0.1 - - [19/Jul/2008:04:40:55 CEST] "POST /articles/22/comments/ new HTTP/1.1" 405 7131 [http://localhost:3000/articles/22](http://localhost:3000/articles/22) -\> /articles/ 22/comments/new

I see its not a get, put or delete.

routes.rb: &nbsp;&nbsp;map.resources :comments &nbsp;&nbsp;map.resources :articles, :has\_many =\> :comments

articles/views/show.html.erb: &nbsp;&nbsp;\<%= link\_to\_remote("new comment", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:update =\> 'editor', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> new\_article\_comment\_path(@article), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:complete =\> visual\_effect(:blind\_down, "editor", :duration =\> 2.5)) %\>

So why didn't I get a get request? Is it a clean code?

I read the RESTful Rails Development from b-simple, but i didn't found a solution for the problem. Maybe the document is a bit outdated. If you have any solution for the problem or a URL I would be glad to hear it \*g\*

Thanks for reading and have a nice day, Patrick

---

<div class="post-metadata">

**Author:** ![Parity](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parity](https://discuss.rubyonrails.org/u/Parity)\
**Post date:** [July 19, 2008, 3:10am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/2 "2008-07-19T03:10:43Z")

</div>

I also tried: :url =\> { :controller =\> "comments", :action =\> "new", :params =\> { :article\_id =\> @article}}

But it didn't help me out ☹

---

<div class="post-metadata">

**Author:** ![bala\_kishore\_puliche](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@bala\_kishore\_puliche](https://discuss.rubyonrails.org/u/bala_kishore_puliche)\
**Post date:** [July 19, 2008, 5:39am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/3 "2008-07-19T05:39:10Z")

</div>

u can do like this in ur routes file map.resources :articles do |article| article.resources :comments end

in ur view for article in @article ur - stuff — \<%= link\_to\_remote(“new comment”,

```
                 :update => 'editor',

                 new_article_comment_path(article),

```

:complete =\> visual\_effect(:blind\_down,

“editor”, :duration =\> 2.5)) %\>

end

i hope it helps 🙂

---

<div class="post-metadata">

**Author:** ![Parity](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parity](https://discuss.rubyonrails.org/u/Parity)\
**Post date:** [July 19, 2008, 9:17am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/4 "2008-07-19T09:17:42Z")

</div>

Hi 🙂

thans for your answer, but it didn't helps :-(. I changed the lines in my lines in routes.rb to: map.resources :articles do |article| &nbsp;&nbsp;&nbsp;&nbsp;article.resources :comments end

(isn't is the old convention?)

And my view to:

\<%= link\_to\_remote("new comment", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:update =\> 'editor', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> new\_article\_comment\_path(@article), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:complete =\> visual\_effect(:blind\_down, "editor", :duration =\> 2.5)) %\>

(without ":url =\>" in front of, i got a compile error)

But it didn't helps.

Bye, Patrick

---

<div class="post-metadata">

**Author:** ![bala\_kishore\_puliche](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@bala\_kishore\_puliche](https://discuss.rubyonrails.org/u/bala_kishore_puliche)\
**Post date:** [July 19, 2008, 9:28am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/5 "2008-07-19T09:28:27Z")

</div>

:o

opzz

u can do like this in routes.rb map.resources :articles do |article| article.resources :comments end

> Hi 🙂
> 
> thans for your answer, but it didn’t helps :-(. I changed the lines in
> 
> my lines in routes.rb to: map.resources :articles do |article|
> 
> ```
> article.resources :comments
> 
> ```
> 
> end

and in ur view

> \<%= link\_to\_remote(“new comment”,
> 
> ```
> :update => 'editor',
> 
> :url => new_article_comments_path(@
> 
> ```
> 
> > article), :complete =\> visual\_effect(:blind\_down,
> > 
> > “editor”, :duration =\> 2.5)) %\>

Note: the url will also depend up on the associations that u use in the models if still any issue :o post ur model and routes file

---

<div class="post-metadata">

**Author:** ![Parity](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parity](https://discuss.rubyonrails.org/u/Parity)\
**Post date:** [July 20, 2008, 1:33pm UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/6 "2008-07-20T13:33:08Z")

</div>

Okay, I post you as much information as i can 🙂

This is my db layout: [http://erdbeere.net/media/db\_layout.png](http://erdbeere.net/media/db_layout.png)

article model: class Article \< ActiveRecord::Base &nbsp;&nbsp;belongs\_to :blog &nbsp;&nbsp;has\_many :comments end

comment model: class Comment \< ActiveRecord::Base &nbsp;&nbsp;belongs\_to :article &nbsp;&nbsp;belongs\_to :user end

routes.rb: &nbsp;&nbsp;map.resources :users &nbsp;&nbsp;map.resources :subscriptions &nbsp;&nbsp;map.resources :blogs # map.resources :comments &nbsp;&nbsp;map.resources :articles do |article| &nbsp;&nbsp;&nbsp;&nbsp;article.resources :comments &nbsp;&nbsp;end

If there is anything i can du to find the problem just send an E- Mails 🙂

Patrick

---

<div class="post-metadata">

**Author:** ![bala\_kishore\_puliche](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@bala\_kishore\_puliche](https://discuss.rubyonrails.org/u/bala_kishore_puliche)\
**Post date:** [July 21, 2008, 7:44am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/7 "2008-07-21T07:44:24Z")

</div>

un comment the map.resources :comments 🙂

and in the view file

---

<div class="post-metadata">

**Author:** ![Parity](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Parity](https://discuss.rubyonrails.org/u/Parity)\
**Post date:** [August 11, 2008, 11:39am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/8 "2008-08-11T11:39:33Z")

</div>

Well, it looks like a problem with js, but I haven't figured out what's wrong. currently i've deactevated the visual effect and use :url to generate the url. It's not great, but it works.

Thanks, Patrick

---

<div class="post-metadata">

**Author:** ![bala\_kishore\_puliche](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@bala\_kishore\_puliche](https://discuss.rubyonrails.org/u/bala_kishore_puliche)\
**Post date:** [August 11, 2008, 11:54am UTC](https://discuss.rubyonrails.org/t/nested-ressource-path-problem/32064/9 "2008-08-11T11:54:29Z")

</div>

One Final try 🙂

models/articles.rb has\_many :comments models/comments.rb belongs\_to :article

controllers comments before\_filter :find\_article def new @comment = Comment.new

end

def create @comment = Comment.new(params[:comment]) if (@article.comments \<\< @comment) redirect\_to article\_url(@article) else render :action =\> :new end

end

private

def find\_article @article\_id = params[:article\_id] return(redirect\_to(articles\_url)) unless @article\_id@article = Article.find(@article\_id) end

views/comments/new.html.erb

\<% form\_for [@article, @comment] do |form| %\>

 Add a Comment

\<%= render :partial =\> ‘form’, :object =\> form %\>

```
<%= submit_tag "Create" %>

```

\<% end %\>

And Finally ur routes file should be

ActionController::Routing::Routes.draw do |map| map.resources :articles do |article|

```
article.resources :comments

```

end

I hope it will work out 🙂 🙂

if u still face any issue :o u can ask regards, Balu
