У меня есть 2 модели Пользователь и Роль , и has_many: через отношения между ними
class User < ApplicationRecord
has_many :user_roles,
has_many :roles, through: :user_roles
end
и
class Role < ApplicationRecord
has_many :user_roles,
has_many :users, :through => :user_roles
end
иотносительная модель
class UserRole < ApplicationRecord
belongs_to :user
belongs_to :role
end
Вопрос в том, как назначить роль конкретному пользователю через консоль.Я пытался с
>User.last.roles = [:admin] (Role which I want to assign has name: admin and role_id: 1)
, но я получаю ошибку
ActiveRecord :: AssociationTypeMismatch (ожидается роль (# 47275896707120), получил: admin, который является экземпляром Symbol (# 47275846312980)))