Lilp
Lilp

Reputation: 971

Update through checkboxes in rails and haml

I have been following the railscast on updating through checkboxes and although i feel i have implemented the logic and the page displays i can't get the logic to behave as it should. I was wondering if anyone could offer any advice here as i feel part of the issue may be my implementation in haml. When i say i cant get the logic to work i mean that the submit button doesn't update anything!

view:

    %h1 Diagnostics
-form_tag complete_admin_diagnostics_path, :method => :put 
/ - for diagnostic in @diagnostics do

%table
  %tr
    %th
    %th User
    %th Message
    %th Device
    %th RELS-Mobile Version
    %th Submitted
    %th Archive
  - @diagnostics.each do |diagnostic| 
    %tr
      %td
        %strong= link_to 'show', admin_diagnostic_path(diagnostic)
      %td
        - if diagnostic.user
          = link_to diagnostic.user.email, [:admin, diagnostic.user]
        - else
          unknown
      %td
        = diagnostic.data["message"]
      %td
        %pre= JSON.pretty_generate(diagnostic.data["device"])
      %td
        = diagnostic.data["appVersion"]
      %td
        = diagnostic.updated_at
      %td
        = check_box_tag "diagnostic_ids[]", diagnostic.id
        / = diagnostic.name


  = submit_tag "Mark as complete"
= paginate @diagnostics

controller

class Admin::DiagnosticsController < Admin::BaseController
  before_filter :diagnostic, :except => [:index, :complete]

  def index
    @diagnostics = DiagnosticInfo.all.order_by(:created_at.desc).page(params[:page]).per(50)
    # @diagnostics = DiagnosticInfo.where(archived: false).entries
  end


  def show
    respond_to do |format|
      format.html
      format.json { render json: @diagnostic }
    end
  end

  def update
    if @diagnostic.update_attributes(params[:diagnostic_info])
      redirect_to admin_diagnostic_path, notice: 'Successfully updated.'
    else
      render action: "edit"
    end
  end

  def edit
  end

  def destroy
    diagnostic.destroy
    redirect_to admin_diagnostics_path
  end

  def complete
    @diagnostic.update_all(["completed_at=?", Time.now], :id => params[:diagnostics_ids]) 
  end


private

  def diagnostic
    @diagnostic = DiagnosticInfo.find(params[:id])
  end
end

Upvotes: 1

Views: 255

Answers (1)

Liyali
Liyali

Reputation: 5693

I believe you need to print out your form tag, otherwise, as you described nothing is being sent:

= form_tag complete_admin_diagnostics_path, :method => :put 

Hope that helps.

Upvotes: 1

Related Questions