0

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 records. 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"?

Backo
  • 18,291
  • 27
  • 103
  • 170
  • http://stackoverflow.com/questions/2182428/rails-nested-form-with-has-many-through-how-to-edit-attributes-of-join-model/2278928#2278928 – Arcolye Nov 26 '12 at 18:28

1 Answers1

-1

I would use the ActiveRecord Callbacks to achieve this :

http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

Dominic Goulet
  • 7,983
  • 7
  • 28
  • 56
  • It doesn't work in my case since I need to add others information by accessing instance variable data (example: `@current_user.id` - it is not possible to access that variable in a model file). – Backo Jul 05 '11 at 14:04