Adding more data on saving 'has_many :through' associated records by keeping use of the "RoR magical\automatic way"
I am using Ruby on Rails 3.0.7 and I followed this post about handling an "has_many :through => checkboxes
" in which, in order to create user-group relationship records for membership purposes, is just passed a group_ids
parameter (that is an array of id values) from check box input fields to the @user.save
method. Using that code all works good in a "RoR magical\automatic way" (RoR set properly user_id
values in the related memberships
database table).
However, on saving, I would like to add some extra information to Membership
r开发者_JAVA百科ecords. That is, (following that post content) when it creates the associated records in the memberships
database table (which database table has id
, user_id
and group_id
columns) I would like to save an extra description information (which, for example, can be represented by a description
column in that memberships
table).
Is it possible to accomplish that by keeping use of the "RoR magical\automatic way"?
I would use the ActiveRecord Callbacks to achieve this :
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
精彩评论