I simply want the simplest solution to check if the user is the current user and based on the answer to render a view slightly different each time.
I have a route on /users/:id for each user which goes to the show of the users_controller
Controller
def show
@user = User.find(params[:id])
respond_to do |format|
format.html #show.html.erb
end
end
I want to change the show.html.erb file in many places. I could try a <% if @user == current_user %> each time but I thought that would create a mess with a lengthy code or many partials.
I could also try to create a second view but I don’t know if I’m working efficiently here:
Controller
def show
@user = User.find(params[:id])
if @user = current_user
redirect_to show_is_current_user
else
respond_to do |format|
format.html #show.html.erb
end
end
end
def show_is_current_user
@user = User.find(params[:id])
respond_to do |format|
format.html #show_is_current_user.html.erb
end
end
Any more efficient solutions than the above?
This will render show.html.erb when users are viewing another user’s profile and
showself.html.erb when showing viewing their own profile: