title: Rendering polymorphic object in Rails
body: <p>For people that only want the question, here it is :</p>
  
  <p><em><strong>Is there a way to specify the folder to look in when you call <code>render</code> on an object? I don't want to specify the view, only the folder to look in.</em></strong></p>
  
  <p>And for people that want context :</p>
  
  <p>I am working on an activity stream system (something that looks like google+/facebook).</p>
  
  <p>I have "Activities", which are exactly like google+ feeds (or facebook, or whatever!). So, I have a simple loop that display each activities, which are bound to one of the following object (polymorphic) : User, Group, Comment, Note. </p>
  
  <p>In my view that render an activity (<code>views/activities/_activity.html.erb</code>), I have</p>
  
  <pre><code>&lt;%= render activity.object %&gt;
  </code></pre>
  
  <p>where <code>activity.object</code> is a reference to the bound object (User, Group, Note, Comment). If it's a user, it goes to <code>views/users/_user.html.erb</code> and renders it. For a group, <code>views/groups/_group.html.erb</code>.</p>
  
  <p>That works just fine. However, I come to the point where the rendering of a group in my activities should not be the same rendering as in the group list page. Is there a way to specify the folder to look in when you call <code>render</code> on an object? So that my :</p>
  
  <pre><code>&lt;%= render activity.object %&gt;
  </code></pre>
  
  <p>would become :</p>
  
  <pre><code>&lt;%= render activity.object, :folder =&gt; 'views/activities/' %&gt;
  </code></pre>
  
  <p>Note that I don't want to specify which view directly, as I don't want to do a case for each of the possible types of objects (User, Group, Note, Comment) in the activity. I want to to have the same behaviour as of right now, which means if it finds a <code>views/activities/_user.html.erb</code>, it would load any user in the activities with that view instead of the one in the <code>views/users/_user.html.erb</code>.</p>
  
  <p>Thanks</p>