rescue_from没有发现错误

时间:2015-02-03 05:16:19

标签: ruby-on-rails ruby-on-rails-4

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/123my/123fdsfdsmy/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 

我没有被重定向。怎么样?

1 个答案:

答案 0 :(得分:0)

我原来,looger.log本身导致错误,应该是:

logger.log Logger::ERROR, "Error, id: #{params[:id]}"