我的 Rails 控制器中有以下模式:
def get_details
# check params for valid input
...
if !valid
render :json, error_info, :status => 400 and return
end
begin
...
...
...
render :json => result, :status => 200 and return
rescue Exception => e
if e.is_a? ActiveRecord::RecordNotFound
render :json => error_info, :status => 404 and return
end
end
end
由于渲染不返回,我必须添加and return
到每个渲染调用,这对我来说似乎不太干燥。这种模式有替代品吗?