Accept flattened values with many-to-many association
I want one model, User, to accept values for another model, Contact::Skill. I'd like a user to be able to update their Contact::Skill attributes from the User edit page. The two models have a many-to-many association with the join table contact_skills_users.
It isn't saving to either the table, contact_skills, or the join table, contact_skills_users. However, looking at the log, I can't find the problem.
AREL (0.3ms) INSERT INTO `contact_skills` (`name`, `created_at`, `updated_at`) VALUES ('joe user skills', '2011-08-15 18:06:30', '2011-08-15 18:06:30')
Contact::Skill Load (0.4ms) SELECT `contact_skills`.* FROM `contact_skills` WHERE `contact_skills`.`id` = 12 LIMIT 1
Contac开发者_如何学Ct::Skill Load (0.5ms) SELECT * FROM `contact_skills` INNER JOIN `contact_skills_users` ON `contact_skills`.id = `contact_skills_users`.skill_id WHERE (`contact_skills_users`.user_id = 3 )
SQL (0.2ms) INSERT INTO `contact_skills_users` (`skill_id`, `user_id`) VALUES (12, 3)
Code from my User model:
has_and_belongs_to_many :skills, :class_name => '::Contact::Skill',
:join_table => 'contact_skills_users'
accepts_flattened_values_for :skills, :value => :name
精彩评论