rails4.0 中 user.has_role?('Admin') 这个方法,是 rails 自带的吗?
2.0.0-p247 :015 >user = User.find(1)
User Load (1.0ms) SELECT users
.* FROM users
WHERE users
.id
= ? LIMIT 1 [["id", 1]]
=> #
2.0.0-p247 :016 > user.has_role?('Admin')
Role Load (1.2ms) SELECT roles
.* FROM roles
INNER JOIN roles_users
ON roles
.id
= roles_users
.role_id
WHERE roles_users
.user_id
= ? AND roles
.name
= 'Admin' LIMIT 1 [["user_id", 1]]
=> false
2.0.0-p247 :017 > role = Role.first
Role Load (0.4ms) SELECT roles
.* FROM roles
ORDER BY roles
.id
ASC LIMIT 1
=> #
2.0.0-p247 :018 > role.has_user?('Admin')
NoMethodError: undefined method `has_user?' for #...