title: Rails 4 - How do I show a different view for the same controller action, based on the current route?
body: <p>I have a standard posts controller with an index action.</p>
  
  <p>At the moment, I am routing this as the home page <code>/</code>, as well as the posts page <code>/posts</code></p>
  
  <pre><code>class PostsController &lt; ApplicationController
  
      def index
      # Logic and finds here
      end
  
  end
  </code></pre>
  
  <p>And in my <code>routes.rb</code> file:</p>
  
  <pre><code>root to: "posts#index"
  get "/posts" =&gt; "posts#index"
  </code></pre>
  
  <p>However, in my view, I would like to lay things out slightly differently depending on whether the route is <code>/posts</code> or just <code>/</code>. Is this possible? And if so, what is the best practice for this?</p>
  
  <p>I was thinking about creating another action in the posts controller, but then I would be replicating the logic, already defined in my index action - which I want to avoid. </p>
  
  <p>I basically want to use the same content, but show a different view.</p>
  
  <p>Any advice or help is greatly appreciated.</p>
  
  <p>Thanks,
  Michael.</p>