如何在获得之前检查
friendly_id条目是否存在?
例如:
def book @book = Book.find(params[:book_id]) end
没关系,但是如果friendly_id存在,我想要检查,例如:
def book if Book.exists?(params[:book_id]) @book = Book.find(params[:book_id]) else #404 not found end
解决方法
从RecordNotFound例外救援==>
def book @book = Book.find(params[:book_id]) #OK rescue ActiveRecord::RecordNotFound => e head :not_found end