Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recreated your scenario in a blank rails app with the routing code and and test you specified, and it worked without a problem, as it should. I'll paste my controller code here since that's the only part you left out:</p> <pre><code>class MessagesController &lt; ApplicationController def index @messages = User.find(params[:user_id]).messages end end </code></pre> <p>If yours is doing basically the same thing, then a routing issue could be caused by a conflict in your routing file, which is what I suspect might be the case. Can you post it? FYI, I wrote an <a href="http://kconrails.com/2010/01/27/route-testing-with-shoulda-in-ruby-on-rails/" rel="nofollow noreferrer">article on testing your routes</a>, and that would be a very good idea because it would catch routing errors early, before they interfere with controllers.</p> <p>Anyway, if you can post your routes I can take a look.</p> <p><strong>UPDATE:</strong> After looking at your routes, there are a couple conflicts. You can have messages as a sub-resource of more than one other resource, but in your messages controller you're going to have to account for the possibility of either a params[:me_id] or params[:profile_id]. It looks like they're both really the user model underneath, so it can be as simple as:</p> <pre><code>@user = User.find(params[:me_id] || params[:profile_id]) </code></pre> <p>and you'll probably want to abstract that out into a method you call with <code>before_filter</code>.</p> <p>The other issue is that you have two overlapping profiles routes, and I'm not sure why. I don't think it's a routing error in the test, because tests bypass the routing engine anyway. I think it's an error in the index view, because it probably contains links to messages with improperly formatted urls. If you have a link to a message, for instance, and you have a @profile object, then you'll need to call them like this:</p> <pre><code>&lt;%= link_to message.name, profile_message_path(@profile, @message) %&gt; </code></pre> <p>However, if you're using non-nested paths like <code>message_path(@message)</code>, it will fail because there are no non-nested message routes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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