我在application_controller.rb處理異常嵌套資源與Mongoid ::錯誤:: DocumentNotFound軌3.1
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from Mongoid::Errors::DocumentNotFound, :with => :render_not_found
def render_not_found
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
然後我打電話
此代碼例如在我的路線做工精細.RB:
resources :posts
的問題是,如果我有一個嵌套的資源像這樣的routes.rb:
resources :users do
resources :posts
end
我有這樣的posts_controller.rb
class PostsController < ApplicationController
end
與此父
現在:用戶不起作用!我在每一個行動的寫從posts_controller.rb此嵌套的資源在未來的工作的罰款如。
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @post }
end
rescue
render_not_found
end
@JatinGanhotra我編輯了這個問題。它可以很好地運行'resources:users'的'resources:posts'輸出。如果我把'資源:用戶做 資源:帖子 結束'。不起作用。謝謝 – hyperrjas
在這裏發佈'rake routes'的輸出。 –