我有类似以下的模型 -
Table: series
- id: integer
- volumes: integer
- title: string
class Series < ActiveRecord::Base
has_many :books, :dependent => :destroy
accepts_nested_attributes_for :books, :reject_if =>
proc { |attributes| attributes[:title].blank? }
validates_associated :books
end
Table: books
- id: integer
- series_id: integer
- title: string
- volume: integer
class Book < ActiveRecord::Base
belongs_to :series
validates :title, :volume, :presence => true
validates :title, :uniqueness =>
{ :scope => :series_id,
:message => 'Book titles must be unique within a series.'}
end
我正在使用nested_form gem来构建一个整合的表单,通过相同的表单输入每本书的系列信息和信息。
当每本书都添加到系列中时,有没有办法自动填充每本书的“音量”属性?
我是否需要修改nested_form生成的JavaScript才能完成此任务,或者我可以在ActiveRecord中做些什么?