我正在尝试将用户定义为管理员,但我无法将其定义为 admin默认为false,由于某种原因,它不允许我定义 控制台中的管理员
我在控制台中键入,我指定的ID是我想要的用户 设置为管理员。
$ u = User.where(:id=>4)
$ u :admin => true
$ u.save
this is in my schema:
create_table "users", force: :cascade do |t|
...
t.boolean "admin", default: false
...
end
那是我的用户模型:
class User < ApplicationRecord
has_many :tables
after_create :assign_default_role
rolify
def assign_default_role
self.add_role(:newuser) if self.roles.blank?
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
这是我用康康建立的能力模型:
class User < ApplicationRecord
has_many :tables
after_create :assign_default_role
rolify
def assign_default_role
self.add_role(:newuser) if self.roles.blank?
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
it shows this in the console;
2.6.0 :047 > u :admin => true
Traceback (most recent call last):
SyntaxError ((irb):47: syntax error, unexpected ':', expecting end-of-
input)
u :admin => true
^