Great! In the users table, we now have a column named
role that we can use to assign different roles to users, such as “editor” or “admin”.
Let’s add a method to the User model that will help us use the role column in our application. Within the class User, beneath the
has_secure_password method, type
def editor? self.role == 'editor' end
We can use this method to determine if a user has the role of editor.
Open db/seeds.rb. We’ve added a user named Mateo with the role ‘editor’. Seed the database with this data
$ bundle exec rake db:seed
We should now be able to use the editor? method to check whether a user has an editor role. First, start the Rails console by running
$ rails console
Then check whether Mateo is an editor
> mateo = User.find_by(email: 'firstname.lastname@example.org') > mateo.editor?