Ruby on Rails相对较新,但我认为我已经掌握了基础知识。我遇到了一个问题,虽然我无法弄清楚并且不知道如何调试。
我的路线很浅:
resources :incident_reports, :shallow => true do
get :thanks, :on => :collection
get :monthly_totals, :on => :collection
post :monthly_totals_download, :on => :collection
resources :supervisory_reviews, :comments
end
rake路线显示了我的期望:
incident_report_supervisory_reviews GET /incident_reports/:incident_report_id/supervisory_reviews(.:format) {:action=>"index", :controller=>"supervisory_reviews"}
POST /incident_reports/:incident_report_id/supervisory_reviews(.:format) {:action=>"create", :controller=>"supervisory_reviews"}
new_incident_report_supervisory_review GET /incident_reports/:incident_report_id/supervisory_reviews/new(.:format) {:action=>"new", :controller=>"supervisory_reviews"}
edit_supervisory_review GET /supervisory_reviews/:id/edit(.:format) {:action=>"edit", :controller=>"supervisory_reviews"}
supervisory_review GET /supervisory_reviews/:id(.:format) {:action=>"show", :controller=>"supervisory_reviews"}
PUT /supervisory_reviews/:id(.:format) {:action=>"update", :controller=>"supervisory_reviews"}
DELETE /supervisory_reviews/:id(.:format) {:action=>"destroy", :controller=>"supervisory_reviews"}
incident_report_comments GET /incident_reports/:incident_report_id/comments(.:format) {:action=>"index", :controller=>"comments"}
POST /incident_reports/:incident_report_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_incident_report_comment GET /incident_reports/:incident_report_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_comment GET /comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
comment GET /comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
我已经在supervisory_reviews_controller中显示和更新以及其他所有内容
def update
@supervisory_review = SupervisoryReview.find(params[:id])
respond_to do |format|
if @supervisory_review.update_attributes(params[:supervisory_review])
format.html { redirect_to(@supervisory_review.incident_report, :notice => 'Supervisory review was successfully updated.') }
format.xml { head :ok }
else
format.html { redirect_to(@supervisory_review.incident_report, :notice => 'An error occurred.') }
format.xml { render :xml => @supervisory_review.errors, :status => :unprocessable_entity }
end
end
end
但是当我试图显示,更新或删除监督评论时 (形式示例)
<form accept-charset="UTF-8" action="/supervisory_reviews/1047" class="edit_supervisory_review" id="edit_supervisory_review_1047" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="ii8Xhygfcr71icNZfljlEkQItpV1+zFKaEn6ZZdYjiE=" />
(看起来对,对吗?)
我得到“您正在寻找的页面不存在”
并且日志说:
开始发帖 “/ supervisory_reviews / 1047”for 10.1.5.24在星期六6月24日17:14:21 -0 400 2011处理方式 SupervisoryReviewsController #update as HTML参数: { “authenticity_token”=&gt;“中ii8Xhygfcr71icNZfljlEkQItpV1 + zFKaEn6ZZdYji E =“,”utf8“=&gt;”â“”“,”id“=&gt;”1047“, “supervisory_review”=&GT; { “inappropriate_reason”=
“”,“advocacy_next_steps”=&gt;“”,“resolution”=&gt;“”, “comments”=&gt;“gfhsdfgsdfg”,“哈 ndling_of_incident “=&gt;” 中”, “建议”=&gt; “中dfsgdfggdfsd”, “need_for_advocacy”= “false”,“incident_resolved”=&gt;“true”,“incident_handled_appropriately”=&gt;“true”} }完成2ms
ActiveRecord :: RecordNotFound(不能 查找没有ID的IncidentReport):
LIB / role_requirement_system.rb:121:在check_roles'
check_roles'
lib/role_requirement_system.rb:121:in
那么为什么要寻找IncidentReport?
最奇怪的部分是评论工作正常,据我所知,两种资源的代码是相同的。
答案 0 :(得分:0)
问题不在于路由,而在于lib / role_requirement_system.rb第121行。也许该代码需要IncidentReport来提供授权。如果您需要更多帮助,请发布该库中的代码。