Shallow nested routes still looking for id of parent
Relatively new to Ruby on Rails but I think I have the basics down. I'm running into one problem though that i just can't figure out and don't really know how to debug.
I have shallow routes:
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
And rake routes shows what i expect:
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) 开发者_如何学JAVA {:action=>"show", :controller=>"comments"}
PUT /comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
i have show and update and everything else defined in 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
but when i try to show, update or delete a supervisory review (form example)
<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=" />
(looks right, right?)
i get "The page you were looking for doesn't exist"
and the log says:
Started POST "/supervisory_reviews/1047" for 10.1.5.24 at Fri Jun 24 17:14:21 -0 400 2011 Processing by SupervisoryReviewsController#update as HTML Parameters: {"authenticity_token"=>"ii8Xhygfcr71icNZfljlEkQItpV1+zFKaEn6ZZdYji E=", "utf8"=>"âo"", "id"=>"1047", "supervisory_review"=>{"inappropriate_reason"=
"", "advocacy_next_steps"=>"", "resolution"=>"", "comments"=>"gfhsdfgsdfg", "ha ndling_of_incident"=>"", "recommendations"=>"dfsgdfggdfsd", "need_for_advocacy"= "false", "incident_resolved"=>"true", "incident_handled_appropriately"=>"true"} } Completed in 2ms
ActiveRecord::RecordNotFound (Couldn't find IncidentReport without an ID):
lib/role_requirement_system.rb:121:incheck_roles' lib/role_requirement_system.rb:121:in
check_roles'
so why is it looking for an IncidentReport?
the weirdest part is Comments work fine and as far as i can tell, the code for both resources is the same.
The issue is not with the routes but with the lib/role_requirement_system.rb line 121. Perhaps that code needs an IncidentReport to provide authorization. Post the code from that library if you need more help.
精彩评论