ruby on rails - Multiple objects from list of names in an array -


enter image description herei'm trying create individual record each name in array. array originates via form in 1 controller , individual records need saved in join (type) table (i know there not "join" tables in mongo, it's best way describe it). running rails 5 mongoid/mongodb.

originating form:

    <%= form_tag create_multiple_batch_keg_index_path, method:          :create |form|%>         <div class="field">         <table class="table table-hover table-condensed">         <thead>         <tr>           <th>select all</th>           <th>keg name</th>         </tr>         </thead>         <tbody>           <% keg.each |batch_keg| %>               <tr>                 <td><%= check_box_tag 'batch_keg_ids[]', batch_keg.id                  -%> </td>                 <td><%= batch_keg.name -%> </td>               </tr>           <% end %>         </tbody>         </table>         </div> 

originating controller params:

    def batch_params      params.require(:batch).permit(:batch_keg_attributes => [keg_id,       :active, :visible, :wholesale_inventory, :taproom_inventory,       :hold_inventory])     end  

join controller

    def create_multiple      batch_keg_ids(params).flatted.map{|ids|       batchkeg.create(:wholesale_inventory => true, :taproom_inventory       => true, :hold_inventory => false, :active => true, :visible =>       true)}redirect_to batches_url     end 

routes

    resources :batch_keg      collection       post :create_multiple       put :update_multiple       :collection      end     end 

i think i've got of process completed (i've worked through several error messages point, i'm stuck). i've searched on inter-webs trying find solution haven't been able find 1 has worked. i'm either a), close not quite there, or b) off course.

it looks i'm getting data need through, unclear on how need use in join controller (i think), i've been on hours , brain mush. feel need create variable in join controller hold data, here headed. in advance suggestions code, or more efficient way this.

well error message pretty clear. passing params parameter batch_kegs_ids, method expecting no parameters. besides, looks batch_kegs_ids method empty (no code). i'd remove entirely (probably not supposed there anyways).

i'd change create_multiple method to

 def create_multiple    params[:batch_keg_ids].each |id|       batchkeg.create(keg_id: id, wholesale_inventory: true, taproom_inventory: true, hold_inventory: false, active: true, visible: true)    end    redirect_to batches_url  end 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -