2015-04-17 19 views
1

我一直在关注通过复选框更新的railscast,尽管我觉得我已经实现了逻辑和页面显示,但是我无法获得逻辑行为。我想知道是否有人可以提供任何建议,因为我觉得这个问题的一部分可能是我在haml中的实现。当我说我不能让逻辑工作,我的意思是提交按钮不会更新任何东西!在rails和haml中通过复选框更新

观点:

%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 

控制器

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 

回答

1

我相信你需要打印出您的表单标签,否则,像你描述的没有被发送:

= form_tag complete_admin_diagnostics_path, :method => :put 

希望有所帮助。

+0

这是完美的解决方案非常感谢! – Lilp