Hi Sergio,

Sorry for the confusion with so many posts.

Ideally, if you have a demo/test application I could modify it to reproduce the 
issues I am having, so you are solving a general issue to help everyone.

I will do some more testing with the def do_edit_associated and see what I find.

If a parent has many children, step-children, and foster-children, and we want 
to edit the parent (family), would the subform action be needed on the parent, 
or only the children, step-chilren, and foster-children?

I would also like to help update the wiki with some more examples of what I 
have found works for certain use cases.

Thanks for all you provide to the community!!

Dennis

From: Sergio Cambra <[email protected]>
Date: Friday, April 7, 2023 at 10:07 AM
To: ActiveScaffold : Ruby on Rails Gem <[email protected]>, 
Dennis Bulgatz <[email protected]>
Subject: Re: Created a show helper, lost the association create
Hi Dennis

I'm a bit lost here. The issue was initially for travels column on sub_tdn
controller, I guess because :subform was not added to travels controller. Then
you said you added it to Odcs controller, and got issue about @column is nil,
but it's a different association in other controller.

Subform must be in the actions of the controller rendering the form (SubTdns)
as the edit_associated action is called in SubTdns and is added by subform
module. And it must be in the actions of the controller for the association's
model (travels controller), as it will read columns from that subform.columns
in that controller.

You can be sure subform is enabled in both in rails console:

SubTdnsController.active_scaffold_config.actions.included? :subform
TravelsController.active_scaffold_config.actions.included? :subform

Then you can override do_edit_associated in SubTdnsController, to debug if all
values are set correctly:

def do_edit_associated
  super
  logger.debug @column.inspect
  logger.debug @parent_record.inspect
end

I think subform is not added to SubTdnsController, so it's rendering
edit_associted.js without executing the code in do_edit_associated. There's no
need to add code to render method.

I don't see any line setting the actions in SubTdnsController, so it should be
using the defaults. Have you changed default actions with
ActiveScaffold.defaults?

Regards

El martes, 4 de abril de 2023 7:50:37 (CEST) Dennis Bulgatz escribió:
> Hi Sergio,
>
> Here is the final “monkey patch” is used to address:
>
>
>   *   Not being able to add new rows to subforms on a new record
>   *   Not being able to get the parent_id tied to an added child record
>
> # wrap the action rendering for ActiveScaffold controllers
> # DCB:  Added this HACK to fix issue where cannot add new child association
> inside sub_tdn edit

> module ActiveScaffold
>   module ActionController #:nodoc:
>     def render(*args, &block)
>       if params[:action] == 'edit_associated'
>         @column =
> active_scaffold_config.columns[params[:child_association]]
> parent_model_name = params[:parent_controller].classify.singularize
> @parent_record ||= parent_model_name.constantize.find(params[:id])
> child_model_name = params[:child_association].classify.singularize @record
> ||= child_model_name.classify.constantize.new
>       end
>
>       #{"association"=>"sub_tdns", "parent_scaffold"=>"tdns",
> "tdn_id"=>"11",
 # "adapter"=>"_list_inline_adapter",
> "controller"=>"sub_tdns", "action"=>"new"} if params[:action] == 'new' &&
> params[:association] == 'sub_tdns' && params[:tdn_id] #No idea why I this
> is not automatic? Need to get the tdn_id for subTdn @record.tdn_id =
> params[:tdn_id]
>       end
>
>
>       if self.class.uses_active_scaffold? && params[:adapter] &&
> @rendering_adapter.nil? && request.xhr?
 @rendering_adapter = true #
> recursion control
>         # if we need an adapter, then we render the actual stuff to a string
> and insert it into the adapter template
 opts = args.any? ? args.first : {}
>         render :partial => params[:adapter][1..-1],
>
>           :locals => {:payload => render_to_string(opts.merge(:layout =>
>           :false), &block).html_safe}, # rubocop:disable
>           :Rails/OutputSafety
 use_full_path => true, :layout => false,
>           ::content_type => :html
>
>         @rendering_adapter = nil # recursion control
>       else
>         super(*args, &block)
>       end
>     end
>   end
> end
>
> From: Dennis Bulgatz <[email protected]>
> Date: Monday, April 3, 2023 at 12:12 PM
> To: Sergio Cambra <[email protected]>, ActiveScaffold : Ruby on Rails Gem
> <[email protected]>
 Subject: Re: Created a show helper, lost
> the association create
> Hi Sergio,
>
> I created a hack that works.. not sure how this could be incorporated into
> AS code generically?  Was thinking I should use build to create the related
> association @record, but this seems to work as is.

> # wrap the action rendering for ActiveScaffold controllers
> module ActiveScaffold
>   module ActionController #:nodoc:
>     def render(*args, &block)
>       puts "@@@@@@@ DCB @@@@@ #{params}"
>       if params[:action] == 'edit_associated'
>         @column =
> active_scaffold_config.columns[params[:child_association]]

>         parent_model_name = params[:parent_controller].classify.singularize
> @parent_record ||= parent_model_name.constantize.find(params[:id]) puts
> "Parent Model Name: #{parent_model_name}"
>         puts "@parent_record.inspect
> #{@parent_record.inspect}<mailto:#{@parent_record.inspect}>"

>         child_model_name = params[:child_association].classify.singularize
>         puts "Child Model Name: #{child_model_name}"
>         @record ||= child_model_name.classify.constantize.new
>         puts "@record.inspect
> #{@record.inspect}<mailto:#{@record.inspect}>"
 puts "@column.inspect
> #{@column.inspect}<mailto:#{@column.inspect}>" puts "@parent_record.inspect
> #{@parent_record.inspect}<mailto:#{@parent_record.inspect}>" puts
> "@record.inspect #{@record.inspect}<mailto:#{@record.inspect}>" end
> From: Dennis Bulgatz <[email protected]>
> Date: Monday, April 3, 2023 at 10:28 AM
> To: Sergio Cambra <[email protected]>, ActiveScaffold : Ruby on Rails Gem
> <[email protected]>
 Subject: Re: Created a show helper, lost
> the association create
> Hi Sergio,
>
> I modified the class that is failing..
>
>
> active_scaffold (ccfc9d71d522)
> lib/active_scaffold/extensions/action_controller_rendering.rb:19:in
> `render'

>
>
> @column was nil, so I put in a setter.
>
>
>
> I have defined all the columns in the travels controller I could think of,
> see below.

>
>
> Not sure why it is trying to render “id”. Any other ideas?
>
>
>
> ----
>
> # wrap the action rendering for ActiveScaffold controllers
> module ActiveScaffold
>   module ActionController #:nodoc:
>     def render(*args, &block)
>       puts "@@@@@@@ DCB @@@@@ #{params}"
>       @column = active_scaffold_config.columns[params[:child_association]]
>       puts "@column.inspect #{@column.inspect}<mailto:#{@column.inspect}>"
>
>
> Started GET
> "/sub_tdns/18/edit_associated?association=sub_tdns&child_association=travel
> s&parent_controller=sub_tdns&parent_scaffold=tdns&tdn_id=22" for ::1 at
> 2023-04-03 10:19:17 -0500

> Processing by SubTdnsController#edit_associated as JS
>
>   Parameters: {"association"=>"sub_tdns", "child_association"=>"travels",
> "parent_controller"=>"sub_tdns", "parent_scaffold"=>"tdns", "tdn_id"=>"22",
> "id"=>"18"}

>   User Load (0.9ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1
> ORDER BY `users`.`id` ASC LIMIT 1

>   Role Load (1.0ms)  SELECT `roles`.* FROM `roles` INNER JOIN
> `role_memberships` ON `roles`.`id` = `role_memberships`.`role_id` WHERE
> `role_memberships`.`user_id` = 1

>   ↳ app/models/user.rb:33:in `collect'
>
> @@@@@@@ DCB @@@@@ {"association"=>"sub_tdns",
> "child_association"=>"travels", "parent_controller"=>"sub_tdns",
> "parent_scaffold"=>"tdns", "tdn_id"=>"22", "controller"=>"sub_tdns",
> "action"=>"edit_associated", "id"=>"18"}

> @column.inspect #<ActiveScaffold::DataStructures::Column:0x00007f819cac9a98
> @name=:travels, @active_record_class=SubTdn(id: integer, sub_tdn_number:
> string, title: string, risk_mitigations: text, updated_by_id: integer,
> tdn_id: integer, ordinal: integer, work_lead_id: integer,
> work_lead_alternate_id: integer, tpoc_id: integer, tpoc_alternate_id:
> integer, pop_begin: date, pop_end: date, introduction: text,
> description_of_work: text, software_classification: text,
> environment_impact: text, data_sensitivity: text, special_requirements:
> text, data_rights_notice: text, created_at: datetime, updated_at:
> datetime), @column=nil, @delegated_association=nil,
> @cache_key="SubTdn#travels",
> @association=#<ActiveScaffold::DataStructures::Association::ActiveRecord:0x
> 00007f819cac98b8
> @association=#<ActiveRecord::Reflection::HasManyReflection:0x00007f819dc1b2
> 10 @name=:travels, @scope=nil, @options={:dependent=>:destroy},
> @active_record=SubTdn(id: integer, sub_tdn_number: string, title: string,
> risk_mitigations: text, updated_by_id: integer, tdn_id: integer, ordinal:
> integer, work_lead_id: integer, work_lead_alternate_id: integer, tpoc_id:
> integer, tpoc_alternate_id: integer, pop_begin: date, pop_end: date,
> introduction: text, description_of_work: text, software_classification:
> text, environment_impact: text, data_sensitivity: text,
> special_requirements: text, data_rights_notice: text, created_at: datetime,
> updated_at: datetime), @klass=Travel(id: integer, line_item_number: string,
> purpose: text, number_of_travelers: integer, number_of_nights: integer,
> number_of_days: integer, from_date: date, to_date: date, destination:
> string, sub_tdn_id: integer, created_at: datetime, updated_at: datetime),
> @plural_name="travels", @constructable=true, @class_name="Travel",
> @inverse_name=:sub_tdn, @foreign_key="sub_tdn_id",
> @active_record_primary_key="id",
> @inverse_of=#<ActiveRecord::Reflection::BelongsToReflection:0x00007f819dcf2
> 940 @name=:sub_tdn, @scope=nil, @options={}, @active_record=Travel(id:
> integer, line_item_number: string, purpose: text, number_of_travelers:
> integer, number_of_nights: integer, number_of_days: integer, from_date:
> date, to_date: date, destination: string, sub_tdn_id: integer, created_at:
> datetime, updated_at: datetime), @klass=SubTdn(id: integer, sub_tdn_number:
> string, title: string, risk_mitigations: text, updated_by_id: integer,
> tdn_id: integer, ordinal: integer, work_lead_id: integer,
> work_lead_alternate_id: integer, tpoc_id: integer, tpoc_alternate_id:
> integer, pop_begin: date, pop_end: date, introduction: text,
> description_of_work: text, software_classification: text,
> environment_impact: text, data_sensitivity: text, special_requirements:
> text, data_rights_notice: text, created_at: datetime, updated_at:
> datetime), @plural_name="sub_tdns", @constructable=true,
> @foreign_key="sub_tdn_id", @class_name="SubTdn", @inverse_name=nil>>>,
> @link=#<Proc:0x00007f81a5839428
> /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/acti
> ve_scaffold-ccfc9d71d522/lib/active_scaffold/core.rb:140>, @autolink=true,
> @table="sub_tdns", @associated_limit=3, @associated_number=true,
> @show_blank_record=true, @send_form_on_update_column=nil,
> @select_columns=[], @text=true, @number=false, @options={},
> @allow_add_existing=true, @css_class="", @required=nil, @sort=true,
> @search_sql=["`travels`.`id`"], @weight=500,
> @actions_for_association_links=[:new, :show, :update],
> @includes=[:travels], @label="7. Travel Requirements">

>   Rendering
> /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/acti
> ve_scaffold-ccfc9d71d522/app/views/active_scaffold_overrides/edit_associated
> .js.erb

>   Rendered
> /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/acti
> ve_scaffold-ccfc9d71d522/app/views/active_scaffold_overrides/edit_associated
> .js.erb (Duration: 2.9ms | Allocations: 1960)

> Completed 500 Internal Server Error in 17ms (ActiveRecord: 1.9ms |
> Allocations: 8755)

>
>
>
>
>
>
> ActionView::Template::Error (undefined method `id' for nil:NilClass):
>
>     1: <%
>
>     2: subform_id = sub_form_list_id(:association => @column.name, :id =>
> @parent_record.id || generated_id(@parent_record) || 99999999999)

>     3: associated_form = render :partial => "form_association_record",
> :object => @record, :locals => {:scope => @scope, :parent_record =>
> @parent_record, :column => @column, :locked => @record.new_record? &&
> @column.association.singular?}

>     4: options = {:singular => false}
>
>     5: if @column.association.singular?
>
>
>
> active_scaffold (ccfc9d71d522)
> app/views/active_scaffold_overrides/edit_associated.js.erb:2

> actionview (6.1.7.3) lib/action_view/base.rb:247:in `public_send'
>
> actionview (6.1.7.3) lib/action_view/base.rb:247:in `_run'
>
> actionview (6.1.7.3) lib/action_view/template.rb:154:in `block in render'
>
> activesupport (6.1.7.3) lib/active_support/notifications.rb:205:in
> `instrument'

> actionview (6.1.7.3) lib/action_view/template.rb:345:in
> `instrument_render_template'

> actionview (6.1.7.3) lib/action_view/template.rb:152:in `render'
>
> actionview (6.1.7.3) lib/action_view/renderer/template_renderer.rb:61:in
> `block (2 levels) in render_template'

> activesupport (6.1.7.3) lib/active_support/notifications.rb:203:in `block in
> instrument'

> activesupport (6.1.7.3)
> lib/active_support/notifications/instrumenter.rb:24:in `instrument'

> activesupport (6.1.7.3) lib/active_support/notifications.rb:203:in
> `instrument'

> actionview (6.1.7.3) lib/action_view/renderer/template_renderer.rb:56:in
> `block in render_template'

> actionview (6.1.7.3) lib/action_view/renderer/template_renderer.rb:75:in
> `render_with_layout'

> actionview (6.1.7.3) lib/action_view/renderer/template_renderer.rb:55:in
> `render_template'

> actionview (6.1.7.3) lib/action_view/renderer/template_renderer.rb:11:in
> `render'

> actionview (6.1.7.3) lib/action_view/renderer/renderer.rb:61:in
> `render_template_to_object'

> actionview (6.1.7.3) lib/action_view/renderer/renderer.rb:29:in
> `render_to_object'

> actionview (6.1.7.3) lib/action_view/rendering.rb:117:in `block in
> _render_template'

> actionview (6.1.7.3) lib/action_view/base.rb:273:in `in_rendering_context'
>
> actionview (6.1.7.3) lib/action_view/rendering.rb:116:in `_render_template'
>
> actionpack (6.1.7.3) lib/action_controller/metal/streaming.rb:218:in
> `_render_template'

> actionview (6.1.7.3) lib/action_view/rendering.rb:103:in `render_to_body'
>
> actionpack (6.1.7.3) lib/action_controller/metal/rendering.rb:52:in
> `render_to_body'

> actionpack (6.1.7.3) lib/action_controller/metal/renderers.rb:142:in
> `render_to_body'

> actionpack (6.1.7.3) lib/abstract_controller/rendering.rb:25:in `render'
>
> actionpack (6.1.7.3) lib/action_controller/metal/rendering.rb:36:in
> `render'

> actionpack (6.1.7.3) lib/action_controller/metal/instrumentation.rb:46:in
> `block (2 levels) in render'

> /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/2.7.0/benchmark.rb:308:in
> `realtime'

> activesupport (6.1.7.3) lib/active_support/core_ext/benchmark.rb:14:in `ms'
>
> actionpack (6.1.7.3) lib/action_controller/metal/instrumentation.rb:46:in
> `block in render'

> actionpack (6.1.7.3) lib/action_controller/metal/instrumentation.rb:86:in
> `cleanup_view_runtime'

> activerecord (6.1.7.3)
> lib/active_record/railties/controller_runtime.rb:34:in
> `cleanup_view_runtime'

> actionpack (6.1.7.3) lib/action_controller/metal/instrumentation.rb:45:in
> `render'

> active_scaffold (ccfc9d71d522)
> lib/active_scaffold/extensions/action_controller_rendering.rb:19:in
> `render'

> wicked_pdf (2.6.3) lib/wicked_pdf/pdf_helper.rb:18:in `render'
>
> actionpack (6.1.7.3) lib/action_controller/metal/implicit_render.rb:35:in
> `default_render'

> actionpack (6.1.7.3)
> lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'

> actionpack (6.1.7.3) lib/abstract_controller/base.rb:228:in
> `process_action'

> actionpack (6.1.7.3) lib/action_controller/metal/rendering.rb:30:in
> `process_action'

> actionpack (6.1.7.3) lib/abstract_controller/callbacks.rb:42:in `block in
> process_action'

> activesupport (6.1.7.3) lib/active_support/callbacks.rb:117:in `block in
> run_callbacks'

> active_scaffold (ccfc9d71d522) lib/active_scaffold/actions/core.rb:312:in
> `clear_storage'

> activesupport (6.1.7.3) lib/active_support/callbacks.rb:126:in `block in
> run_callbacks'

> actiontext (6.1.7.3) lib/action_text/rendering.rb:20:in `with_renderer'
>
> actiontext (6.1.7.3) lib/action_text/engine.rb:59:in `block (4 levels) in
> <class:Engine>'

> activesupport (6.1.7.3) lib/active_support/callbacks.rb:126:in
> `instance_exec'

> activesupport (6.1.7.3) lib/active_support/callbacks.rb:126:in `block in
> run_callbacks'

> activesupport (6.1.7.3) lib/active_support/callbacks.rb:137:in
> `run_callbacks'

> actionpack (6.1.7.3) lib/abstract_controller/callbacks.rb:41:in
> `process_action'

> actionpack (6.1.7.3) lib/action_controller/metal/rescue.rb:22:in
> `process_action'

> actionpack (6.1.7.3) lib/action_controller/metal/instrumentation.rb:34:in
> `block in process_action'

> activesupport (6.1.7.3) lib/active_support/notifications.rb:203:in `block in
> instrument'

> activesupport (6.1.7.3)
> lib/active_support/notifications/instrumenter.rb:24:in `instrument'

> activesupport (6.1.7.3) lib/active_support/notifications.rb:203:in
> `instrument'

> actionpack (6.1.7.3) lib/action_controller/metal/instrumentation.rb:33:in
> `process_action'

> actionpack (6.1.7.3) lib/action_controller/metal/params_wrapper.rb:249:in
> `process_action'

> activerecord (6.1.7.3)
> lib/active_record/railties/controller_runtime.rb:27:in `process_action'

> actionpack (6.1.7.3) lib/abstract_controller/base.rb:165:in `process'
>
> actionview (6.1.7.3) lib/action_view/rendering.rb:39:in `process'
>
> actionpack (6.1.7.3) lib/action_controller/metal.rb:190:in `dispatch'
>
> actionpack (6.1.7.3) lib/action_controller/metal.rb:254:in `dispatch'
>
> actionpack (6.1.7.3) lib/action_dispatch/routing/route_set.rb:50:in
> `dispatch'

> actionpack (6.1.7.3) lib/action_dispatch/routing/route_set.rb:33:in `serve'
>
> actionpack (6.1.7.3) lib/action_dispatch/journey/router.rb:50:in `block in
> serve'

> actionpack (6.1.7.3) lib/action_dispatch/journey/router.rb:32:in `each'
>
> actionpack (6.1.7.3) lib/action_dispatch/journey/router.rb:32:in `serve'
>
> actionpack (6.1.7.3) lib/action_dispatch/routing/route_set.rb:842:in `call'
>
> warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
>
> warden (1.2.9) lib/warden/manager.rb:34:in `catch'
>
> warden (1.2.9) lib/warden/manager.rb:34:in `call'
>
> rack (2.2.6.4) lib/rack/tempfile_reaper.rb:15:in `call'
>
> rack (2.2.6.4) lib/rack/etag.rb:27:in `call'
>
> rack (2.2.6.4) lib/rack/conditional_get.rb:27:in `call'
>
> rack (2.2.6.4) lib/rack/head.rb:12:in `call'
>
> actionpack (6.1.7.3) lib/action_dispatch/http/permissions_policy.rb:22:in
> `call'

> actionpack (6.1.7.3)
> lib/action_dispatch/http/content_security_policy.rb:19:in `call'

> rack (2.2.6.4) lib/rack/session/abstract/id.rb:266:in `context'
>
> rack (2.2.6.4) lib/rack/session/abstract/id.rb:260:in `call'
>
> actionpack (6.1.7.3) lib/action_dispatch/middleware/cookies.rb:697:in
> `call'

> activerecord (6.1.7.3) lib/active_record/migration.rb:601:in `call'
>
> actionpack (6.1.7.3) lib/action_dispatch/middleware/callbacks.rb:27:in
> `block in call'

> activesupport (6.1.7.3) lib/active_support/callbacks.rb:98:in
> `run_callbacks'

> actionpack (6.1.7.3) lib/action_dispatch/middleware/callbacks.rb:26:in
> `call'

> actionpack (6.1.7.3) lib/action_dispatch/middleware/executor.rb:14:in
> `call'

> actionpack (6.1.7.3)
> lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'

> actionpack (6.1.7.3)
> lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'

> web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
>
> web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
>
> web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
>
> web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
>
> actionpack (6.1.7.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in
> `call'

> railties (6.1.7.3) lib/rails/rack/logger.rb:37:in `call_app'
>
> railties (6.1.7.3) lib/rails/rack/logger.rb:26:in `block in call'
>
> activesupport (6.1.7.3) lib/active_support/tagged_logging.rb:99:in `block in
> tagged'

> activesupport (6.1.7.3) lib/active_support/tagged_logging.rb:37:in `tagged'
>
> activesupport (6.1.7.3) lib/active_support/tagged_logging.rb:99:in `tagged'
>
> railties (6.1.7.3) lib/rails/rack/logger.rb:26:in `call'
>
> sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
>
> actionpack (6.1.7.3) lib/action_dispatch/middleware/remote_ip.rb:81:in
> `call'

> request_store (1.5.1) lib/request_store/middleware.rb:19:in `call'
>
> actionpack (6.1.7.3) lib/action_dispatch/middleware/request_id.rb:26:in
> `call'

> rack (2.2.6.4) lib/rack/method_override.rb:24:in `call'
>
> rack (2.2.6.4) lib/rack/runtime.rb:22:in `call'
>
> activesupport (6.1.7.3)
> lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'

> actionpack (6.1.7.3) lib/action_dispatch/middleware/executor.rb:14:in
> `call'

> actionpack (6.1.7.3) lib/action_dispatch/middleware/static.rb:24:in `call'
>
> rack (2.2.6.4) lib/rack/sendfile.rb:110:in `call'
>
> actionpack (6.1.7.3)
> lib/action_dispatch/middleware/host_authorization.rb:148:in `call'

> rack-mini-profiler (2.3.4) lib/mini_profiler/profiler.rb:393:in `call'
>
> webpacker (5.4.4) lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
>
> rack-proxy (0.7.6) lib/rack/proxy.rb:87:in `call'
>
> railties (6.1.7.3) lib/rails/engine.rb:539:in `call'
>
> puma (5.6.5) lib/puma/configuration.rb:252:in `call'
>
> puma (5.6.5) lib/puma/request.rb:77:in `block in handle_request'
>
> puma (5.6.5) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
>
> puma (5.6.5) lib/puma/request.rb:76:in `handle_request'
>
> puma (5.6.5) lib/puma/server.rb:443:in `process_client'
>
> puma (5.6.5) lib/puma/thread_pool.rb:147:in `block in spawn_thread'
>
>
>
> lass TravelsController < ApplicationController
>
>   before_action :check_resource_permissions
>
>   active_scaffold :"travel" do |conf|
>     conf.label = '7. TRAVEL REQUIREMENTS'
>
> conf.columns = [:line_item_number, :purpose, :number_of_travelers,
> :number_of_nights, :number_of_days,
>                     :from_date, :to_date, :destination]
>
>
>     conf.subform.columns = [:line_item_number, :purpose,
> :number_of_travelers, :number_of_nights, :number_of_days,
>                     :from_date, :to_date, :destination]
>
>
>
>     conf.list.columns = [:line_item_number, :purpose, :number_of_travelers,
> :number_of_nights, :number_of_days,
>                     :from_date, :to_date, :destination, :sub_tdn]
>
>     conf.create.columns = :line_item_number, :purpose, :number_of_travelers,
> :number_of_nights, :number_of_days,
>                     :from_date, :to_date, :destination
>
>
>     conf.update.columns = :line_item_number, :purpose, :number_of_travelers,
> :number_of_nights, :number_of_days,
>                     :from_date, :to_date, :destination
>
>     conf.actions = [:create, :delete, :list, :show, :search, :export,
> :subform]
 conf.export.default_file_format = 'xlsx' # or 'csv'
>
>
>   end
>
>   private
>
>   def create_authorized?
>     current_user.has_role_name?("TDN_Manager")
>   end
>
>   def export_authorized?
>     current_user.has_tdn_access?
>   end
>
>   def check_resource_permissions
>     unless current_user.has_tdn_access?
>       redirect_to welcome_index_path, alert: "User #{current_user.to_label}
> does not have #{controller_name.humanize.upcase} Access"
 end
>   end
>
> end
>
> From: Sergio Cambra <[email protected]>
> Date: Monday, April 3, 2023 at 5:51 AM
> To: ActiveScaffold : Ruby on Rails Gem <[email protected]>,
> Dennis Bulgatz <[email protected]>
 Subject: Re: Created a show
> helper, lost the association create
> Hi
>
> The line setting @column is in actions/subform.rb, in do_edit_associated:
>
> @column = active_scaffold_config.columns[params[:child_association]]
>
> What's the value of child_association param in the request? Is that column
> included in conf.columns?
>
> Regards
>
> El lunes, 3 de abril de 2023 9:24:52 (CEST) Dennis Bulgatz escribió:
>
> > Hi Sergio,
> >
> >
> >
> > Doh.. I eventually figured out that the conf.actions needs to include
> > subform!  Hopefully this will help someone in the future.
> >
> >
> >
> > class OdcsController < ApplicationController
> >
> >
> >
> >   before_action :check_resource_permissions
> >
> >
> >
> >   active_scaffold :"odc" do |conf|
> >
> >     conf.label = '8.  MISCELANEOUS PURCHASES AND OTHER DIRECT COSTS
> >     (ODCS)'
> >     conf.subform.columns =[:line_item_number, :description, :qty,
> > :
> > :justification ] conf.columns = [:line_item_number, :description, :qty,
> > :justification, :sub_tdn ] conf.actions = [:delete, :list, :show,
> > ::search,
> > :export, :subform] conf.export.default_file_format = 'xlsx' # or 'csv'
> > :
> >   end
> >
> >
> >
> > But I am getting a new error when I try to add Another child record, for
> > example with “Create Another Odc”
> >
> >
> >
> >
> > [cid:[email protected]]
> >
> >
> >
> >
> >
> > ActionView::Template::Error (undefined method `name' for nil:NilClass):
> >
> >
> >
> >     1: <%
> >
> >
> >
> >     2: subform_id = sub_form_list_id(:association => @column.name, :id =>
> >
> > @parent_record.id || generated_id(@parent_record) || 99999999999)
> >
> >
> >
> >     3: associated_form = render :partial => "form_association_record",
> > :
> > :object => @record, :locals => {:scope => @scope, :parent_record =>
> >
> > @parent_record, :column => @column, :locked => @record.new_record? &&
> > @column.association.singular?}
> >
> >
> >
> >     4: options = {:singular => false}
> >
> >
> >
> >     5: if @column.association.singular?
> >
> >
> >
> >
> >
> > active_scaffold (ccfc9d71d522)
> > app/views/active_scaffold_overrides/edit_associated.js.erb:2
> >
> >
> >
> > actionview (6.1.7.3) lib/action_view/base.rb:247:in `public_send'
> >
> >
> >
> > actionview (6.1.7.3) lib/action_view/base.rb:247:in `_run'
> >
> >
> >
> > Not sure if this is an AS bug?  Or a problem somewhere in my code?
> >
> >
> >
> > Thanks
> >
> >
> >
> > Dennis
> >
> >
> >
> > From: Dennis Bulgatz <[email protected]>
> > Date: Saturday, April 1, 2023 at 11:08 PM
> > To: Sergio Cambra <[email protected]>, ActiveScaffold : Ruby on Rails
> > Gem
> > <[email protected]> Subject: Re: Created a show helper,
> > lost
> > the association create
> > Hi Sergio,
> >
> >
> >
> > Thanks again.  I did as you suggested and created an override for
> > column_renders_as.  For some reason, I get “Subform is not enabled” when
> > I
> > force subform.
> >
> >
> >
> > What would a controller config look like to enable/disable the subform?
> > What is the method checking for the subform being enabled?
> >
> >
> >
> >   def column_renders_as(column)
> >
> >     puts "YES, we are here! #{column.name.inspect}"
> >     if column.name == :travels
> >
> >       logger.debug "@@@@@@@@@"
> >       logger.debug "column.association.nil? : #{column.association.nil?}"
> >       logger.debug "column.form_ui : #{column.form_ui}"
> >       logger.debug
> >
> > "!active_scaffold_config_for(column.association.klass).actions.include?(:s
> > u
 bform) :
> > #{!active_scaffold_config_for(column.association.klass).actions.include?(:
> > s
 ubform)}" logger.debug "@@@@@@@@@"
> >
> >       return :subform
> >
> >     end
> >
> >
> >
> >     if column.is_a? ActiveScaffold::DataStructures::ActionColumns
> >
> >       return :subsection
> >
> >     elsif column.active_record_class.locking_column.to_s ==
> >     column.name.to_s
> >
> > or column.form_ui == :hidden return :hidden
> >
> >     elsif column.association.nil? or column.form_ui or
> >
> > !active_scaffold_config_for(column.association.klass).actions.include?(:su
> > b
 form) return :field
> >
> >     else
> >
> >       return :subform
> >
> >     end
> >
> >   end
> >
> >
> >
> >
> >  Rendered
> >
> > /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/act
> > i
> > ve_scaffold-ccfc9d71d522/app/views/active_scaffold_overrides/_form_messag
> > es. html.erb (Duration: 0.4ms | Allocations: 147)
> >
> >
> >
> > YES, we are here! :travels
> >
> >
> >
> > @@@@@@@@@
> >
> >
> >
> > column.association.nil? : false
> >
> >
> >
> > column.form_ui :
> >
> >
> >
> > !active_scaffold_config_for(column.association.klass).actions.include?(:su
> > bf
 orm) : true
> >
> >
> >
> > @@@@@@@@@
> >
> >
> >
> >   Rendered
> >
> > /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/act
> > i
> > ve_scaffold-ccfc9d71d522/app/views/active_scaffold_overrides/_form.html.e
> > rb (Duration: 32.8ms | Allocations: 9586)
> >
> >
> >
> >   Rendered
> >
> > /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/act
> > i
> > ve_scaffold-ccfc9d71d522/app/views/active_scaffold_overrides/_base_form.h
> > tml .erb (Duration: 37.9ms | Allocations: 14980)
> >
> >
> >
> >   Rendered
> >
> > /Users/dbulgatz/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/bundler/gems/act
> > i
> > ve_scaffold-ccfc9d71d522/app/views/active_scaffold_overrides/_update_form
> > .ht ml.erb (Duration: 38.3ms | Allocations: 15249)
> >
> >
> >
> > Completed 500 Internal Server Error in 84ms (ActiveRecord: 12.1ms |
> > Allocations: 41633)
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ActionView::Template::Error (Subform is not enabled. Please enable it or
> > remove any references in your configuration (e.g. config.subform.columns
> > =
> > [...]).):
> >
> >
> >
> >     19:     <%= render :partial => 'form', :locals => { :columns =>
> >     column,
> > :
> > :subsection_id => subsection_id, :form_action => form_action, :scope =>
> >
> > scope } %>
> >
> >
> >
> >     20:   </li>
> >
> >
> >
> >     21:   <% end %>
> >
> >
> >
> >     22:   <% elsif renders_as == :subform and authorized -%>
> >
> >
> >
> >     23:   <%= content_tag :li, active_scaffold_subform_attributes(column,
> >
> > column_css_class) do %>
> >
> >
> >
> >     24:     <%= render_column(column, @record, renders_as, scope) %>
> >
> >
> >
> >     25:   <% end %>
> >
> >
> >
> >
> >
> > active_scaffold (ccfc9d71d522) lib/active_scaffold/config/core.rb:250:in
> > `[]'
> >
> >
> >
> > Here is my controller:
> >
> >
> >
> > class SubTdnsController < ApplicationController
> >
> >   active_scaffold :"sub_tdn" do |conf|
> >
> >     conf.columns = [:title, :ordinal, :work_lead,
> >
> >
> >
> >                     :pop_begin, :pop_end,
> >                     :introduction, :description_of_work,
> >                     :
> >                     ::software_classification,
> >                     :
> >                     :environment_impact, :data_sensitivity,
> >                     :
> >                     ::special_requirements,
> >                     :
> >                     :travels, :odcs, :gfis, :deliverables,
> >                     :
> >                     ::data_rights_notice ]
> >
> >
> >
> >     conf.create.columns = [
> >
> >
> >
> >       :travels, :odcs, :gfis, :deliverables,
> >       :title, :ordinal, :work_lead,
> >       :pop_begin, :pop_end,
> >       :introduction, :description_of_work, :software_classification,
> >       :environment_impact, :data_sensitivity, :special_requirements,
> >     :
> >     :
> >     :data_rights_notice ]
> >
> >
> >
> >     conf.update.columns = [
> >
> >
> >
> >       :travels, :odcs, :gfis, :deliverables,
> >       :title, :ordinal, :work_lead,
> >       :pop_begin, :pop_end,
> >       :introduction, :description_of_work, :software_classification,
> >       :environment_impact, :data_sensitivity, :special_requirements,
> >     :
> >     :
> >     :data_rights_notice ]
> >
> >
> >
> >     conf.list.columns = :sub_tdn_number, :title
> >     conf.columns[:introduction].label =  "1. Introduction"
> >     conf.columns[:description_of_work].label =  "2. Description of Work"
> >     conf.columns[:software_classification].label =  "3. Software
> >
> > Classification" conf.columns[:environment_impact].label =  "4.
> > Environment
> > Impact" conf.columns[:data_sensitivity].label =  "5. Data Sensitivity"
> > conf.columns[:special_requirements].label =  "6. Special Requirements"
> > conf.columns[:travels].label =       "7. Travel Requirements"
> >
> >     conf.columns[:odcs].label =          "8. Other Direct Costs"
> >     conf.columns[:gfis].label =          "9. Government Furnished Items"
> >     conf.columns[:deliverables].label=   "10. Deliverables/Milestones"
> >     conf.columns[:data_rights_notice].label=   "11. Data Rights Notice"
> >
> >
> >
> >     conf.columns[:introduction].form_ui = :text_editor
> >     conf.columns[:description_of_work].form_ui = :text_editor
> >     conf.columns[:software_classification].form_ui = :text_editor
> >     conf.columns[:environment_impact].form_ui = :text_editor
> >     conf.columns[:data_sensitivity].form_ui = :text_editor
> >     conf.columns[:special_requirements].form_ui = :text_editor
> >     conf.columns[:data_rights_notice].form_ui = :text_editor
> >
> >
> >
> >     conf.action_links.add 'get_pdf', :type => :member, controller:
> > :
> > :sub_tdns, action: :show, page: true, :parameters => {format: :pdf}
> >
> >
> >
> >     #conf.show.link.page = true
> >
> >   end
> >
> >
> >
> > From: Sergio Cambra <[email protected]>
> > Date: Friday, March 31, 2023 at 9:06 AM
> > To: ActiveScaffold : Ruby on Rails Gem <[email protected]>
> > Cc: Dennis Bulgatz <[email protected]>
> > Subject: Re: Created a show helper, lost the association create
> > Hi Dennis
> >
> >
> >
> > There is a helper method, column_renders_as, which should return :subform
> > for column travels. It would return :field if subform action has been
> > excluded from travels controller, form_ui has been set for the column, or
> > a
 helper _form_column has been defined for the column. Defining
> > sub_tdn_travels_show_column shouldn't affect.
> >
> >
> >
> > Was sub_tdn_travels_show_column being called in create/update form? Or
> > was
> > it displaying a list of checkboxes instead of subform?
> >
> >
> >
> > What method is called with the super line? Super would call another
> > method
> > with the same name, and ActiveScaffold doesn't define
> > sub_tdn_travels_form_column, so you must have defined that method
> > somewhere
 else.
> >
> >
> >
> > Regards
> >
> >
> >
> > El jueves, 30 de marzo de 2023 0:32:39 (CEST) Dennis Bulgatz escribió:
> >
> > > Hi Sergio,
> > >
> > >
> > >
> > > i have a resource that a column with a has_many association.
> > >
> > >
> > >
> > > For the "show" action I have a column helper that renders the children
> > > as
> > > a
> > > table.
> > >
> > >
> > >
> > >   def sub_tdn_travels_*show_column*(record, input_name)
> > >
> > >
> > >
> > >     display_standard_table(
> > >
> > >
> > >
> > >       [
> > >
> > >
> > >
> > >         { :name => 'line_item_number', :display_name => 'Item' },
> > >         { :name => 'purpose', :display_name => 'Purpose' },
> > >         { :name => 'number_of_travelers', :display_name =>
> > >         'Traveler(s)'
> > >         },
> > >         { :name => 'number_of_nights', :display_name => 'Night(s)' },
> > >         { :name => 'number_of_days', :display_name => 'Days(s)'},
> > >         { :name => 'from_date', :display_name => 'From'},
> > >         { :name => 'to_date', :display_name => 'To'},
> > >         { :name => 'destination', :display_name => 'Destination'}
> > >
> > >
> > >
> > >     ], record.travels)
> > >
> > >
> > >
> > >   end
> > >
> > >
> > >
> > > This has stopped the create/update actions on the parent from showing
> > > the
> > > AS form/partial that can create new child records.
> > >
> > >
> > >
> > > Not sure what is going on, but can i restore partial with a call in the
> > >
> > >
> > >
> > > helper method:
> > >
> > >   def sub_tdn_travels_*form_column*(record, input_name)
> > >
> > >
> > >
> > >       super(record,input_name) #THIS IS NOT RIGHT, but the idea is to
> > >       use
> > >
> > >
> > >
> > > default partial
> > >
> > >
> > >
> > >   end
> > >
> > >
> > >
> > > Thanks!
> > >
> > >
> > >
> > > Dennis
>
>
>
>
>
>



-- 
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/MN0PR19MB5825847E5A7A42459A221D24F9979%40MN0PR19MB5825.namprd19.prod.outlook.com.

Reply via email to