I am trying to build a grid in rails for data entry. It has rows and columns, and rows and columns are joined by cells. In my opinion, I need the grid to be able to process the βnewβ rows and columns at the border, so if you enter them and then send, they are automatically generated and their common cells connect to them correctly, I want to be able to do this without js.
Nested Rails attributes cannot be displayed for a new record or for a new column, they can only do one or the other. The reason is that they are nested specifically in one of the two models, and depending on which one they are not nested in, there will be no identifier (since it does not exist yet), and when it is pushed through accepts_nested_attributes_for on the model of the Grid level, they will be attached only to the new object created for everyone in which they were nested.
How can I handle this? Should I override rails handling of nested attributes?
My models look like this: By the way:
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
gzuki source share