Post Meta

Bookmarks

  • Delicious
  • Digg
  • Reddit
  • Magnolia
  • Newsvine
  • Furl
  • Facebook
  • Technorati

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.

  1. Do a template override in ActiveScaffold (first read the how-to)
  2. Install RedBox modal windows plugin (quick help here)
  3. 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") %>;


Related posts

Leave A Comment

+ -