Hi, so I'm new to rails development, and I'm following a book called
Practical Rails: Social Networking Sites. There's a user role system
that the book develops, each user has a one or more roles and vice
versa. So I have the tables users, roles and roles_users (which
connects users to roles and vice versa).
In the Role model I have has_and_belongs_to_many :users and in the
User model I have has_and_belongs_to_many: roles.
To get the joint table I ran the command: script/generate migration
CreateRolesUsersJoin and in the 2010301_create_roles_users_join.rb
file I have the following:
create_table :roles_users, :id => false do |t|
t.column :role_id, :integer, :null => false
t.column :user_id, :integer, :null => false
admin_user = User.create(:username => 'Admin',
:email => 'email@example.com',
:profile => 'Site Administrator',
:pwd => 'admin',
:pwd_confirmation => 'admin')
admin_role = Role.find_by_name('Administrator')
admin_user.roles << admin_role
so after that I run db:migrate and I expect that a new user called
Admin should be created int eh database and the roles_users database
should have one record in it connecting user Admin and role
Administrator... but my databases are empty.
Any suggestion? I'm using rails 2.3.5 and I think the book uses an
older version so I suspect something to do with a version difference,
but not sure.
Thanks in advance.