0
我試圖通過複選框實現更新我的條目的方式,以便通過複選框可以清除選定的條目,並將完成的條目顯示在單獨的視圖上。我通過複選框跟蹤了更新條目的railscast,但是我收到了上面的錯誤,我似乎無法解決它。未定義的方法`update_all'爲零:NilClass
控制器:
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)
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
查看:
%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.data
= submit_tag "Mark as complete"
= paginate @diagnostics
您沒有設置'@ diagnostic'實例變量,要用於「完成」行動。 –
你可能可以擴展這個解釋嗎? – Lilp