0

Ive setup a application with two basic user roles.

A admin who can manage everything and a normal user and can create things (jobs & clients) but can not delete.

I'm a bit stumped though as to how can assign roles to the users. I assume it would be a case of adding a role column to my database? As user's are only created by the admin user. I need to add some sort of collection select to my form?

Can anyone point me in the right direction?

Edit: I tried the One role per user instructions as detailed on the cancan wiki here but i'm recieving the error uninitialized constant User::ROLES

Keva161
  • 2,623
  • 9
  • 44
  • 68

1 Answers1

1

Found an answer :)

I inserted this code..

  ROLES = %w[admin user]

    def role_symbols
      [role.to_sym]
    end

Into my User model and put <%= f.collection_select :role, User::ROLES, :to_s, :humanize %> into my form :)

Keva161
  • 2,623
  • 9
  • 44
  • 68