Reputation: 18338
I have a ruby on rails controller that will display a different form for a logged out user than a logged in user.
What is the best way to approach this? (Is the below way ok?)
class UsersController < ApplicationController
def index
if logged_in && is_admin
render 'admin_index'
end
#use default index
end
end
Upvotes: 3
Views: 3487
Reputation: 19203
You can always do this:
if condition
render :page and return
Just as you can do this:
if condition
redirect_to and return
Upvotes: 1
Reputation: 3069
Sure thats fine except you might get a 'cannot render action twice' type error (if im admin and logged in it still would try to render the default after rendering the admin action)
class UsersController < ApplicationController
def index
if logged_in && is_admin
render 'admin_index'
else
render
end
end
end
might be better
Upvotes: 5