LoginSignup
4
5

More than 1 year has passed since last update.

Railsの非推奨を分かっているものはあえて無視する

Last updated at Posted at 2015-03-12

rails_adminで警告が出て五月蝿かったので、
把握しているものは表示しないようにしてみました.

initializersに配置

payload[:message]に非推奨のメッセージが入っているので、
適当に判定してnextでブロックから抜けるようにしています.

config/initializers/notifications.rb
ActiveSupport::Notifications.subscribe 'deprecation.rails' do |name, start, finish, id, payload|

  # OPTIMIZE あえて非推奨の警告を無視
  next if payload[:message].include? 'config/initializers/rails_admin.rb'

  if Rails.env.test?
    $stderr.puts(payload[:message])
  else
    logger = Rails.logger
    logger.warn payload[:message]
    logger.debug payload[:callstack].join("\n  ") if logger.debug?
  end
end

:notifyするように設定

コンフィグで以下のように:notifyを指定するだけです.

  • config/environments/development.rb
  • config/environments/test.rb
config.active_support.deprecation = :notify

プロダクションには何度も非推奨の警告を表示しても仕方ないので:silenceを指定しておけばいいと思います.

  • config/environments/production.rb
config.active_support.deprecation = :silence
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5