Running into a situation where the second column is not updating as expected when opening a record to edit via a subform. When you open to edit, the values in the second column are not constrained based on the value in the first column. It works fine on create and even works in edit if you update the first column the second will then be constrained as expected. Here is my setup:
class Document < ApplicationRecord
has_many :geologies
has_many :geology_types, through: :geologies
has_many :geology_techniques, through: :geologies
end
class Geology < ApplicationRecord
belongs_to :document
belongs_to :geology_type
belongs_to :geology_technique
end
class GeologyTechnique < ApplicationRecord
belongs_to :geology_type
has_many :geologies
has_many :documents, through: :geologies
end
class DocumentsController < ApplicationController
active_scaffold :"document" do |config|
config.columns = [:name, :geologies]
end
end
class GeologiesController < ApplicationController
active_scaffold :"geology" do |config|
config.subform.columns = [:geology_type, :geology_technique]
config.columns[:geology_type].form_ui = 'select'
config.columns[:geology_technique].form_ui = 'select'
config.columns[:geology_type].update_columns = :geology_technique
end
end
module GeologiesHelper
def options_for_association_conditions(association,record)
{'geology_techniques.geology_type_id' => @record.geology_type_id}
else
super
end
end
end
When I create a new Document and add a new Geology via the subform it correctly constrains the geology_technique based on the value in geology_type. When I edit the Document the subform correctly displays the geology_type and geology_technique but the values in geology_technique are not constrained as expected. I need to update the value in geology_type before the geology_technique is constrained. Interestingly, if I go directly to the geologies controller and edit a Geology the geology_technique is correctly constrained by the selected geology_type. But it is not happening when editing via the subform from the documents controller. So it seems like it is something to do with the association but I have not been able to figure it out.
How can I get the second column to be constrained when the record is initially opened in edit in the documents controller?