I have a standard posts controller with an index action.
At the moment, I am routing this as the home page /
, as well as the posts page /posts
class PostsController < ApplicationController
def index
# Logic and finds here
end
end
And in my routes.rb
file:
root to: "posts#index"
get "/posts" => "posts#index"
However, in my view, I would like to lay things out slightly differently depending on whether the route is /posts
or just /
. Is this possible? And if so, what is the best practice for this?
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.
I basically want to use the same content, but show a different view.
Any advice or help is greatly appreciated.
Thanks, Michael.