Chaining form fields via subform

11 views
Skip to first unread message

Big Mister T

unread,
Nov 7, 2019, 8:00:56 AM11/7/19
to ActiveScaffold : Ruby on Rails Gem

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)   
if association.name == :geology_technique
{'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?

Sergio Cambra

unread,
Nov 7, 2019, 8:17:37 AM11/7/19
to actives...@googlegroups.com, Big Mister T

Add geologies helper to documents controller, because when edit is open, render is done by documents controller, even subform, while changing column in subform calls geologies controller.

 

Regards,

Sergio

 

--
You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails Gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activescaffol...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/activescaffold/8d53e4ae-6502-4bd3-9b5e-b4d44932d9eb%40googlegroups.com.



Big Mister T

unread,
Nov 7, 2019, 9:44:30 AM11/7/19
to ActiveScaffold : Ruby on Rails Gem
Success.  Thanks very much, Sergio!

To unsubscribe from this group and stop receiving emails from it, send an email to activescaffold+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages