的official page有此片段的代碼:我不明白,避免DoubleRenderError
def show
@book = Book.find(params[:id])
if @book.special?
render :action => "special_show" and return
end
render :action => "regular_show"
end
爲什麼不是這等同?
def show
@book = Book.find(params[:id])
if @book.special?
render :action => "special_show"
return
end
render :action => "regular_show"
end
或者,爲什麼不使用它?
def show
@book = Book.find(params[:id])
if @book.special?
render :action => "special_show" and return
else
render :action => "regular_show"
end
end
我不明白render ... and return
第一次渲染後的回報如何?那會不對? – Geo
不要從'ActiveRecord :: RecordNotFound'救援。 Rails默認使用404頁面([source](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/show_exceptions.rb))。 – molf