you might override the "do_create" method in the controller. Use the one at lib/active_scaffold/actions/create.rb and change it as needed.
On Mon, Mar 21, 2011 at 8:55 PM, ruinen <[email protected]> wrote: > I am trying to use ActiveScaffold to create multiple records at once. > I have a successfully used Form Overrides (https://github.com/ > activescaffold/active_scaffold/wiki/Form-Overrides) to change a HTML > SELECT to allow multiple selections: > > module TrainingsHelper > def unit_form_column(record, options) > select :record, :unit, Unit.find.collect { |item| [item.title, > item.id]}, options, {:multiple=>true} > end > end > > When I select multiple options and click 'Create' I get an expected > error, since I am now submitting an array for one of the fields where > a single value is expected. > > Processing TrainingsController#create [POST] > Parameters: {"authenticity_token"=>"xx", "record"=>{"unit"=>["124", > "125", "126"], "comment"=>""}, "commit"=>"Create", "eid"=>"xx", > "nested"=>"true", "parent_column"=>"trainings", > "parent_model"=>"User", "controller"=>"trainings", "action"=>"create"} > User Load (1.0ms) SELECT * FROM `users` WHERE (`users`.`id` = '4') > LIMIT 1 > Unit Load (0.0ms) SELECT * FROM `units` WHERE (`units`.`id` IN > (124,125, 126)) > ActiveRecord::AssociationTypeMismatch (Unit(#18426) expected, got > Array(#15772)): > > I was hoping that I could use the before_create_save [controller > method] or before_validation [model callback] to do something like > pick up the 'unit' array and create the additional records (i.e. 125 & > 126) and then just set unit to 124 so final record can get saved > normally. However the error occurs before i hit the before_create_save > or before_validation. Is there anything else I can try? > > -- > You received this message because you are subscribed to the Google Groups > "ActiveScaffold : Ruby on Rails plugin" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/activescaffold?hl=en. > > -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en.
