Reputation: 653
I am new to Rails. I want the existence of only one admin in my Rails application.
I followed this guide: https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-Role Option 2: Adding an admin attribute
I am stuck to this current_user.update_attribute :admin, true
, I am not sure where should I run this command. I tried on the terminal but it does not work (it is a Rails commands, silly me) but I am not sure what to do with it.
I guess I have to create a new method like:
def update_to_admin
current_user.update_attribute :admin, true
end
and the call current_user.update_to_admin
somewhere
BUT (if I am right in this approach)
1) Where should I build this method? (I am using devise)
2) How can I use this method once I write it? From the terminal?
Upvotes: 0
Views: 73
Reputation: 14038
You would run that method in a rails console rails c
on the terminal will open the console.
You will need to find your user or just grab the first one: user = User.first
Then update them: user.update_attribute(:admin, true)
Upvotes: 2