I'm not sure I have understood you, the record you get in before_create_save 
is the store which you are creating/editing, and you can use the params hash 
too.

On Lunes, 24 de Agosto de 2009 19:57:58 helmerj escribió:
> I have a couple of models, that all have a storagelocation.
>
> The complete storagelocation comprises the following "storage_types"
>
> 1. building
> 2. room
> 3. device
> 4. box
> 5. spot
>
> building > room > device > box > spot
>
> I have a StorageLocation model that uses the awesome_nested_set
> plugin. So each spot is in a box, each box is in a device, each device
> is in a room and each room is in a building. Using the
> awesome_nested_set plugin the needed lft and rgt fields are set when a
> Storagelocation is save.
>
> When I use the storagelocations controller I have, as of now to
> simplify things, 5 drop down menus, which are populated using a
> collection select filtering for the storage_types 1-5. All works here.
>
> So what I would like to use this for is the following:
>
> I have a couple of items that actually do get stored. So let's assume
> I have a sample XX and I would like to store it in a spot in box and
> the box is in a device, ... you get my drift.
> So instead of saving all of the storagelocation tree I only want to
> save the last child of the storagelocation tree, so in a perfect case
> I would like to save the id of the spot in the box as the
> storagelocation_id with the sample XY.
>
> I use a form field override by rendering the following partial:
>
> <div id="storagelocation">
> <strong>Storage Location</strong><br />
>
>     <table>
>       <tr>
>         <th>Building</th>
>         <td>
>           <%= collection_select(:store, :building_id,
> Storagelocation.find(:all,
>
>                                 :conditions => { :storage_type =>
>
> 'building'} ), :id, :storage_name,
>                                 {:prompt => true}, {:style => "width:
> 200px"}) %>
>         </td>
>       </tr>
>
>       <tr>
>         <th>Room</th>
>         <td><%= collection_select(:store, :room_id,
> Storagelocation.find(:all,
>
>                                   :conditions => { :storage_type =>
>
> 'room'} ), :id, :storage_name,
>                                   {:prompt => true},{:style => "width:
> 200px"}) %>
>         </td>
>       </tr>
>       <tr>
>         <th>Device</th>
>         <td>
>           <%= collection_select(:store, :device_id,
> Storagelocation.find(:all,
>
>                                 :conditions => { :storage_type =>
>
> 'device'} ), :id, :storage_name,
>                                 {:prompt => true},{:style => "width:
> 200px"}) %>
>         </td>
>       </tr>
>       <tr>
>         <th>Box</th>
>         <td>
>           <%= collection_select(:store, :box_id, Storagelocation.find
> (:all,
>
>                                 :conditions => { :storage_type =>
>
> 'box'} ), :id, :storage_name,
>                                {:prompt => true},{:style => "width:
> 200px"}) %>
>         </td>
>       </tr>
>       <tr>
>         <th>Spot</th>
>         <td>
>           <%= collection_select(:store, :spot_id, Storagelocation.find
> (:all,
>
>                                 :conditions => { :storage_type =>
>
> 'spot'} ), :id, :storage_name,
>                                 {:prompt => true},{:style => "width:
> 200px"}) %>
>       </td>
>       <tr>
>     </table>
> </div>
>
> So in addition to the regular record dataset I have a second dataset
> store that has the ids of each selected storagelocation.
>
> What I tried to get this started is this:
>
> def before_create_save(record, store)
>     record.user_id = @current_user.id
>     record.storagelocation_id = store.spot_id
>   end
>
> But it seems that As can only handle a single record set not two.
>
> ERROR:
> ArgumentError (wrong number of arguments (1 for 2)):
> haml (2.0.9) lib/sass/plugin/rails.rb:19:in `process'
>
>
> So I thought I assign the store.spot_id to an instance variable and
> then do the following:
>
> @store_id = store.spot_id
> def before_create_save(record, store)
>     record.user_id = @current_user.id
>     record.storagelocation_id = @spot_id
>   end
>
> ERROR:
> NameError (undefined local variable or method `store' for
> AntibodiesController:Class):
>
>
> Is there a way to save information into two models that comes from one
> form? I also will have to check for the last child, set storage_types
> and asset_types...
>
> Any help would be greatly appreciated!!
> 
-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to