开发者

rails 3 show 404

开发者 https://www.devze.com 2023-02-18 02:01 出处:网络
how to render 404 instead NoMethodError in People#show error 开发者_Go百科 the code def show @person = Person.find(params[:id])

how to render 404 instead NoMethodError in People#show error

开发者_Go百科

the code

def show
  @person = Person.find(params[:id])
   respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @person }
  end
end


NoMethodError will render a 500 in production mode, however if you want to also render a 404 status in the headers in development mode, you can do the following:

 redirect_to :status => 404

To render the standard 404 page, you can check out the top answer here.

0

精彩评论

暂无评论...
验证码 换一张
取 消