class MyController < ApplicationController
before_action :set_data, only: [:show, :edit, :update, :destroy]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_data
respond_to :html
def show
respond_with(@item)
end
private
def set_data
@item = Item.find params[:id]
end
def invalid_data
logger.log "Error, id: #{params[:id]}"
redirect_to some_url, error: 'Error123'
end
end
但是,当我转到my/123
或my/123fdsfds
或my/fdsfds
时,我会收到标准错误&#34;屏幕:
ArgumentError in MyController#show
comparison of String with 0 failed
logger.log "Error, id: #{params[:id]}"
redirect_to some_url, error: 'Error123'
end
end
我没有被重定向。怎么样?
答案 0 :(得分:0)
我原来,looger.log本身导致错误,应该是:
logger.log Logger::ERROR, "Error, id: #{params[:id]}"