Skip to content

Instantly share code, notes, and snippets.

@ahk
Created May 7, 2010
Embed
What would you like to do?
class Grid < ActiveRecord::Base
has_many :rows
has_many :columns
has_many :cells, :through => :rows
accepts_nested_attributes_for :rows,
:allow_destroy => true,
:reject_if => lambda {|a| a[:description].blank? }
accepts_nested_attributes_for :columns,
:allow_destroy => true,
:reject_if => lambda {|a| a[:description].blank? }
end
class Column < ActiveRecord::Base
belongs_to :grid
has_many :cells, :dependent => :destroy
has_many :rows, :through => :grid
end
class Row < ActiveRecord::Base
belongs_to :grid
has_many :cells, :dependent => :destroy
has_many :columns, :through => :grid
accepts_nested_attributes_for :cells
end
class Cell < ActiveRecord::Base
belongs_to :row
belongs_to :column
has_one :grid, :through => :row
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment