user1811817
user1811817

Reputation: 33

How do i make a user an admin

I am creating a website in Ruby and I would like to have the option to sign up as an admin or a user. I have created the sign up system using devise and I would like to be able to give different permissions to different users, i.e Admins and Users. Thanks guys.

Upvotes: 0

Views: 72

Answers (4)

Neo
Neo

Reputation: 5463

you can use devise + cancan and define roles like user and admin to separate common user and application admin.

class User < AB
  has_many :roles

  def is_admin?
    roles.include?(:admin)
  end
end

class Role < AB

end

and then check it in cancan's definition file like this

  can :update, Model do |model|
    user.admin?
  end 

this video give you detail about it http://railscasts.com/episodes/192-authorization-with-cancan

Upvotes: 0

nilay
nilay

Reputation: 365

You can add boolean fields admin and users into your User model. So while creating you can assign admin or user role.

This question is answered here:
how to define user roles

Upvotes: 0

Mark Stanislav
Mark Stanislav

Reputation: 979

Here's a post about using Devise and CanCan to accomplish what you are looking for.

Upvotes: 1

t56k
t56k

Reputation: 6981

There's a comprehensive guide here.

Upvotes: 1

Related Questions