Sunday, 18 August 2013

What are the best practices when designing restricted areas in rails?

What are the best practices when designing restricted areas in rails?

being newish to rails I wanted to get some advice from the community on
how to setup restricted areas. I just started using Devise and have read
about a few different methods for redirecting/rendering views based on if
a user is logged in or not and I'm wondering what the best way to go about
it is.
Currently, when I want a logged in user to have a different view of a page
then a non-logged in user I've been handling it in the controller. For
instance:
class CollectionsController < ApplicationController
before_filter :authenticate_user!, except: [:index, :show]
def index
@collections = Collection.all
if current_user
render :admin
else
render :index
end
end
end
In which case :admin and :index correspond to
views/collections/admin.html.haml and views/collections/index.html.haml
respectively. The admin view is similar in layout to the index view but
has links to the edit, update, create, etc.
Is this the best way going about it?
EDIT: I was also considering trying out an authorization gem like CanCan
but wasn't sure if that would be overkill.

No comments:

Post a Comment