Question

i'm using rails_admin i have three models (Poll) (MobileUser) (MobileUserPoll)

class Poll <  ActiveRecord::Base
has_many :mobile_users_polls
has_and_belongs_to_many :mobile_users , :join_table => :mobile_users_polls

class MobileUsersPoll < ActiveRecord::Base
after_save :send_notifications

when creating a poll and choosing mobile users (using multiselect provided by rails_admin) the MobileUsersPoll records are being created automatically, the problem is the (after_save) callback is don't work anyone have any idea?

thanks

Was it helpful?

Solution

From the Rails website:

"You should use has_many :through if you need validations, callbacks, or extra attributes on the join model."

Therefore, change the association setup to a has_many :through association. See here for further info:

http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association

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