javascript_for_update_column helper

6 views
Skip to first unread message

Dennis Bulgatz

unread,
Oct 8, 2023, 10:57:18 AM10/8/23
to ActiveScaffold : Ruby on Rails Gem
Hi Sergio,

I have a use case as follows:

A "User" has many "disciplines" through discipline_memberships and has many "skills" through skill_memberships.  A skill belongs to a discipline.

When editing a user, say we add a discipline_membership of "software developer".  Easy enough.  But I'd like to then automatically build all the skill_memberships for that user
corresponding to the skill belonging to the discipline. java, ruby, python, perl, c++ etc.

Not sure if javascript_for_update_column helper is the right approach to trigger building new skill_membership associations when a discipline_membership is added?  If so, any examples of how this would work?  Or is there a higher-level helper that could build associations"

Thanks

Dennis

Sergio Cambra

unread,
Oct 26, 2023, 3:29:08 PM10/26/23
to ActiveScaffold : Ruby on Rails Gem
You can add the associated records in the after_render_field method in the controller, and set them to an instance variable. Then you can create render_field.js.erb, with <%= render :super %> and add code to render the rows for the new associated records. However you will have to add some JS to find the parent element to add these rows, as they will be in a different subform if I understand correctly.

--
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/6c1055d6-ad95-4255-80a0-d67d5c6c3643n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages