Question

I am following the rails guide http://guides.rubyonrails.org/association_basics.html to make a has_and_belongs_to_many relation between the user and event while in the table users_events I have another attributes like admin:boolean and timestamps.

When the user create the event I want that the boolean be true, while other users participate into that event the admin boolean will be false.

How can I assign values to these attributes?

users_events table
---------------------
t.references :user
t.references :event
t.boolean :admin
t.timestamps

Thanks in advance!!

Was it helpful?

Solution

You may have to use the has_many :through association instead of has_and_belongs_to_many.

This way you will be able to create the UserEvent manually to assign your attributes.

More details on: http://guides.rubyonrails.org/association_basics.html#choosing-between-has-many-through-and-has-and-belongs-to-many

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top