0

I've read through the many threads on this topic and still can't see why my code won't work. I have the following:

class User < ActiveRecord::Base

has_many :user_roles
has_many :user_groups, :through => :user_roles

#define attributes and validations
accepts_nested_attributes_for :user_roles
accepts_nested_attributes_for :user_groups

attr_accessible <some_attributes>, :user_groups_attributes, :user_roles_attributes


class UserRole < ActiveRecord::Base

belongs_to :user
belongs_to :user_group

attr_accessible :role_name

class UserGroup < ActiveRecord::Base

has_many :user_roles
has_many :users, :through => :user_roles

attr_accessible :user_group_name

Via the rails console I'm trying to test creating a user group with associated with a user as follows (before I create the form to do the same)

user = User.last
<user details listed>
user.user_groups.create(:user_group_name => "test", :role_name => "test")

Gives can't mass assign attribute role_name. If anyone can see what I've done wrong I'd really appreciate the help.

0 Answers0