0
我知道這個錯誤來自我的控制器中的查找方法,但我不太清楚如何去解決錯誤。我試圖創建一個完整的方法,所以通過複選框可以將帖子存檔並從索引頁面中刪除。到目前爲止,路由還沒有:id在相關的完整的管理診斷,所以我想知道這是否也是一個問題在這裏。另外我使用的軌道3Mongoid無效查找錯誤軌道
錯誤
Mongoid ::錯誤:: InvalidFind在管理:: DiagnosticsController#完整
Problem:
Calling Document.find with nil is invalid.
Summary:
Document.find expects the parameters to be 1 or more ids, and will return a single document if 1 id is provided, otherwise an array of documents if multiple ids are provided.
Resolution:
Most likely this is caused by passing parameters directly through to the find, and the parameter either is not present or the key from which it is accessed is incorrect.
視圖
%h1 Diagnostics
%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 'A Checkbox', method: :put, data: { confirm: "Are you sure?" }
= link_to 'Save', complete_admin_diagnostics_path, method: :put, data: { confirm: "Are you sure?" }
= paginate @diagnostics
控制器
class Admin::DiagnosticsController < Admin::BaseController
before_filter :diagnostic, :except => [:index]
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_attribute(:completed_at, Time.now)
redirect_to @diagnostics, notice: "Todo item completed"
return
end
# def complete
# DiagnosticInfo.update_all(["Archive=?", Time.now], :id => params[:diagnostic_ids])
# params[:diagnostic_ids]
# # redirect_to admin_diagnostics_path
# end
private
def diagnostic
@diagnostic = DiagnosticInfo.find(params[:id])
end
end