Success.  Thanks very much, Sergio!

On Thursday, November 7, 2019 at 7:17:37 AM UTC-6, Sergio Cambra wrote:
>
> El miércoles, 6 de noviembre de 2019 21:49:24 (CET) Big Mister T escribió:
>
> 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? 
>
>  
>
> 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 [email protected] <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/activescaffold/8d53e4ae-6502-4bd3-9b5e-b4d44932d9eb%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/activescaffold/8d53e4ae-6502-4bd3-9b5e-b4d44932d9eb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/activescaffold/d43ec508-2f7d-455e-bb59-0dfabbae1a6a%40googlegroups.com.

Reply via email to