samedi 8 août 2015

How to set an user as admin [rails]

i'm trying to set an user as admin and this is the code I wrote so far:

app/controllers/users_controller.rb

class UsersController < ApplicationController

before_action :admin_user,     only: [:destroy]
..
..
def admin_user
      redirect_to(root_url) unless current_user && current_user.admin?
end


db/seeds.rb

User.create!(name:  "admin",
         surname: "admin",
             email: "admin@1.it",
             password:              "password",
             password_confirmation: "password",
             admin: true)

So, when I create an user with these specs it doesn't work as well: typing 'localhost:3000/users,it redirects me to root_url instead of users page.. Can someone help me? what's wrong with this code? Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire