An useful extension for associated forms.
Associated forms in ActiveScaffold — has_many, habtm — are represented visually by using subforms. These subforms offers you a select box to choose an existing item/relation, and, automatically shows a new blank record to add new items/relations.
The blank record is shown as a table row instead of a list, so when you have many columns the view is ugly. In the following example I’ve replaced the new blank record section with a link to a modal window — in this way you can add new related items nicely even when these have many columns.
- Do a template override in ActiveScaffold (first read the how-to)
- Install RedBox modal windows plugin (quick help here)
- In “_form_association_footer.rhtml” template override add a “Create New” link to remote RedBox call after the “Add Existing” button.
1 2 3 | <%= button_to_function as_('Add Existing'), "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', Element.previous(this).value), {asynchronous: true, evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id})}})" %>; <%= link_to_remote_redbox(as_('Create New') + " " + column.label, {:url => column.name.to_s, :method => :get}, :class => "buttonstyle") %>; |


