1

What should be the right response for a RecordNotFound Error when doing something like this:

def destroy
    @post = current_user.posts.find(params[:id])
    @post.destroy

    head :no_content
  end
4

1 回答 1

0

你可以这样写:

def destroy
  @post = current_user.posts.find(params[:id])
  rescue ActiveRecord::RecordNotFound
  flash[:notice] = "Record Not Found"
  @post .destroy

  head :no_content
end
于 2013-01-14T06:52:15.390 回答