admin user / devise

62 views
Skip to first unread message

Joe Guerra

unread,
Jan 30, 2017, 4:48:21 PM1/30/17
to Ruby on Rails: Talk
I know there is a current_user method for devise, but how do you check if the user is admin?  (I've got a user flagged as admin).

I have a admin menu that I'd like to enable / disable when admin is logged in.

Thanks,
Joe  


Colin Law

unread,
Jan 30, 2017, 4:54:41 PM1/30/17
to Ruby on Rails: Talk
On 30 January 2017 at 21:48, Joe Guerra <jgu...@jginfosys.com> wrote:
> I know there is a current_user method for devise, but how do you check if
> the user is admin? (I've got a user flagged as admin).

Do you mean that you have a column in users table named admin which is
true or false? if so then just test current_user.admin

Colin

Joe Guerra

unread,
Jan 30, 2017, 5:01:34 PM1/30/17
to Ruby on Rails: Talk
Yes, lol.  That easy.  I'll try it.

Active Catalyst - Bill Felton

unread,
Jan 31, 2017, 1:49:20 AM1/31/17
to rubyonra...@googlegroups.com
Is it a boolean column?
We wind up setting @user = current_user, and then checking 
if @user.admin  
#current_user.admin should work just as well if you don’t need to hang on to the actual signed in user.
end
Otherwise, 
@user.<column_name> == “admin”   #(or whatever you use)

cheers,
Bill

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e4ec59a4-4bb5-4e0f-9490-d659d6350a47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Guerra

unread,
Jan 31, 2017, 10:31:58 PM1/31/17
to Ruby on Rails: Talk
Thanks, that worked !
Reply all
Reply to author
Forward
0 new messages