mardi 3 novembre 2015

how to send ids for records in a table using check boxes in haml rails

Okay first time asking a question on here so bare with me. I have an issue with my rails application (version 1.9) where I wish to send ids relating to a table full of models that I am iterating through and showing. I have the checkbox_tag setup I believe properly and am attempting to encapsulate the whole table in a form_tag in order to send the ids back to the controller so that I can edit them in a different view. My routes section of the code that pertains to this is


routes.rb

match '/workflow_queue/index', :to => 'WorkflowQueue#index', :as => 'workflow_queue'
match '/workflow_queue/import_tendays', :to => 'WorkflowQueue#import', :as => 'workflow_queue_import'
match '/workflow_queue/import_finish', :to => 'WorkflowQueue#import_finish', :as => 'workflow_queue_import_finish'
match '/workflow_queue/delete', :to => 'WorkflowQueue#delete', :as => 'workflow_queue_delete'
resources :workflowqueue do
  member do
    post 'edit_multiple'    
  end
end


The routes file should create a path with edit_multiple_workflowqueue_path given what is said in the documentation and it seems to be doing that because when I go to display the partial that houses this code..


_form_workflows.html.haml

=form_tag  edit_multiple_workflowqueue_path  do

  %thead
    %tr

      %th= 'Entity_Type'
      %th= 'Entity_ID'
      %th= 'Workflow ID'
      %th= 'Message'
      %th= ''
      %th= ''


  %tbody
    - for wf in @workflowtasks
      %tr

        %td= wf.entity_type
        %td= wf.entity_id
        %td= wf.workflow_id
        %td= wf.message
        %td= check_box_tag "wf_ids[]", wf.id
        %td= link_to "Destroy", workflow_queue_delete_path(wf)
=submit_tag "Edit Checked"


I keep getting this error No route matches {:action=>"edit_multiple", :controller=>"workflowqueue"}. This doesn't make much sense to me though because inside my controller code it clearly has an edit_multiple action defined and the name of the controller inside the route is the exact same name being used for every other action the controller handles. Meaning that if I do a rake routes that name for the controller shows up for the new, edit, and delete methods rails created automatically. I really don't understand why it can't find the method inside the controller. The controller code is..


class WorkflowQueueController < ApplicationController

  def index
    @workflows = WorkflowQueue.all

    @title = 'Workflow Queues'

  end

  def import
    @title = 'Import Tenday Notices'
    @form_errors = []
  end

  def import_finish
    @title = 'Imported Tendays'
    if params[:xml]
      @start_time = Time.now

      @filename = params[:xml].original_filename

      errors_and_imports = WorkflowQueue.read_tenday_xml(params[:xml].read)
      @errors = errors_and_imports[:errors]
      @extra_imports = errors_and_imports[:extra_imports]

      @form_errors = []

      @workflowtasks = WorkflowQueue.all
    else
      @form_errors = [ 'Please select a file to upload.' ]
      render 'import'
    end
  end

  def edit_multiple
    @workflows = WorkflowQueue.all
    render 'index'
  end

  def delete
    url_string = request.url
    id = url_string.split('.')[3]
    workflow_to_be_deleted = WorkflowQueue.find(id.to_i).destroy

    @workflowtasks = WorkflowQueue.all
    @title = 'Imported Tendays'
    @form_errors = []
    @errors = []
  end

end


The code inside edit_multiple is throwaway code just to see if the method is being called. Please if anyone could help I would be greatly appreciated. To sum it all up when I click the submit_tag "Edit Checked" I want to save the id's that have been checked inside the params hash and have it sent to the edit_multiple method of the workflowqueue controller. Thanks!

Aucun commentaire:

Enregistrer un commentaire