cancan

31 views
Skip to first unread message

Avi

unread,
Oct 5, 2012, 7:46:32 AM10/5/12
to rubyonra...@googlegroups.com
Hello All,

Does cancan works without fetching roles data from db?
Can we give permissions accordingly?
Can we configure those roles like enum classes in java or in any config file?

Thanks

Walter Lee Davis

unread,
Oct 5, 2012, 10:47:49 AM10/5/12
to rubyonra...@googlegroups.com
The default setup (all I've ever done) is to configure the various roles in the ability.rb class file. If you look at the documentation or the RailsCast, that's what they start with. As far as looking up the current user to determine what role that user has, CanCan assumes you're using some authentication, which probably means looking up the user from the database, and that the authentication creates a current_user method that returns an object representing that authenticated user. CanCan doesn't get into the business of creating that current_user, though.

Walter

Avi

unread,
Oct 8, 2012, 3:32:44 AM10/8/12
to rubyonra...@googlegroups.com
Thanks for the reply.

How cancan can be used for restricting the methods in controllers which has no models ?

Walter Lee Davis

unread,
Oct 8, 2012, 7:59:54 AM10/8/12
to rubyonra...@googlegroups.com

On Oct 8, 2012, at 3:32 AM, Avi wrote:

> Thanks for the reply.
>
> How cancan can be used for restricting the methods in controllers which has no models ?

By dealing with the model that represents current_user or its local equivalent. The controller in question does not have to be the UsersController by any means, as long as you have authenticated at some point, and have a current_user somewhere in your application. Lots more here: https://github.com/ryanb/cancan/wiki/Authorizing-Controller-Actions

Walter

Jordon Bedwell

unread,
Oct 8, 2012, 8:12:14 AM10/8/12
to rubyonra...@googlegroups.com
On Mon, Oct 8, 2012 at 6:59 AM, Walter Lee Davis <wa...@wdstudio.com> wrote:
> By dealing with the model that represents current_user or its local equivalent. The controller in question does not have to be the UsersController by any means, as long as you have authenticated at some point, and have a current_user somewhere in your application. Lots more here: https://github.com/ryanb/cancan/wiki/Authorizing-Controller-Actions

You don't really need to authenticate since you can blanket deny based
on new user.
Reply all
Reply to author
Forward
0 new messages