RoR的神奇\\自动方式"通过保持使用的&QUOT相关的记录;:添加上保存更多的数据“通过的has_many” [英] Adding more data on saving 'has_many :through' associated records by keeping use of the "RoR magical\automatic way"
问题描述
我使用on Rails的Ruby的3.0.7和我跟着的这篇文章了解处理一个的has_many:通过=>复选框
,其中,以创造为目的的会员用户组关系的记录,只是通过了 group_ids
参数(即ID值的数组)的复选框,输入字段的 @ user.save
方法。使用code一切运作良好的回报率神奇\\自动的方式(RoR的正确设置 USER_ID
值相关的成员
数据库表)。
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).
然而,对储蓄,我想一些额外的信息添加到成员
记录。也就是说,(下面那个帖子的内容)时,它会在成员的相关记录
数据库表(数据库表有 ID
, USER_ID
和 GROUP_ID
列)我想保存一个额外的描述信息(例如,可重新由描述psented $ p $
在该列成员
表)。
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).
是否有可能实现这一目标通过保持使用的神奇的回报率\\自动的方式?
推荐答案
我会使用ActiveRecord的回调来实现这一点:
I would use the ActiveRecord Callbacks to achieve this :
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
这篇关于RoR的神奇\\自动方式"通过保持使用的&QUOT相关的记录;:添加上保存更多的数据“通过的has_many”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!