0

私は次のようなモデルを持っています-

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_formgemを使用して、同じフォームからシリーズ情報と各本の情報を入力するための統合フォームを作成しています。

各本がシリーズに追加されるときに、各本の「ボリューム」属性を自動的に設定する方法はありますか?

これを実現するには、nested_formで生成されたJavaScriptを変更する必要がありますか、それともActiveRecordでできることはありますか?

4

0 に答える 0