Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Although the syntax to deinfe resource and model relationship is similar, you shouldn't be fooled into thinking that a resource maps to a model. Read what <a href="http://dablog.rubypal.com/2008/3/23/splitting-hairs-over-resource" rel="nofollow noreferrer">David Black has to say</a>.</p> <p>The problem you're having is with the routes you're generating. Using the nested syntax like so:</p> <pre><code>map.resources :users do |user| user.resources :posts user.resources :comments user.resources :comments_received end </code></pre> <p>And then running <code>'rake routes'</code>, gives me (amongst loads of other stuff!):</p> <pre><code> users GET /users {:action=&gt;"index", :controller=&gt;"users"} user_posts GET /users/:user_id/posts {:action=&gt;"index", :controller=&gt;"posts"} user_comments GET /users/:user_id/comments {:action=&gt;"index", :controller=&gt;"comments"} user_comments_received_index GET /users/:user_id/comments_received {:action=&gt;"index", :controller=&gt;"comments_received"} </code></pre> <p>So it appears that rails is adding _index to the end of the comments_received route. I'll admit I don't know why (something to do with clashing with the other comments route?) but it explains your problem.</p> <p>An nicer alternative might be to define a collection action on your comments resource, like so:</p> <pre><code>map.resources :users do |user| user.resources :posts user.resources :comments, :collection =&gt; {:received =&gt; :get} end </code></pre> <p>This will give you the following routes:</p> <pre><code> users GET /users {:action=&gt;"index", :controller=&gt;"users"} user_posts GET /users/:user_id/posts {:action=&gt;"index", :controller=&gt;"posts"} user_comments GET /users/:user_id/comments {:action=&gt;"index", :controller=&gt;"comments"} received_user_comments GET /users/:user_id/comments/received {:action=&gt;"received", :controller=&gt;"comments"} </code></pre> <p>Note: the received action is now on the comments controller</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload