Rails 2.3-style plugins and deprecation warnings running task in Heroku

Ruby on-RailsHerokuRuby on-Rails-Plugins

Ruby on-Rails Problem Overview


I'm upgrading to Rails 3.2, and running rake db:migrate gives me several errors of the form:

> DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from at /app/Rakefile:7)

What's perplexing is that my vendor/plugins directory is empty -- is there another plugins directory that it's referencing?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Are you using Heroku?

> Heroku will inject plugins in Rails 3.x applications .. > To avoid this > injection in Rails 3, include the rails_12factor gem in your > application. (Heroku Ruby Support 2013-10-26)

The rails_12factor gem is also required in rails 4.

> If this gem is not present in your application, you will receive a > warning while deploying, and your assets and logs will not be > functional. (Rails 4 on Heroku 2013-10-26)

As recently as 2013-08, heroku always injected plugins in rails 3 apps, even apps with the recommended gems. This was an issue with the ruby buildpack, and was fixed by PR 11, merged on 2013-08-06.

Solution 2 - Ruby on-Rails

You can try

::ActiveSupport::Deprecation.silenced = true

in your production.rb since it's just noise.

Solution 3 - Ruby on-Rails

in config/environment.rb add:

ActiveSupport::Deprecation.silenced = true 

before initializing rails, like so:

# Load the rails application                                                                                                                                             
require File.expand_path('../application', __FILE__)

ActiveSupport::Deprecation.silenced = true                                                                                                                               

# Initialize the rails application                                                                                                                                       
MyApp::Application.initialize!

Similarly to disable warnings in rake tasks insert the silencing config near the top of your Rakefile:

# Load the rails application                                                                                                                                             
require File.expand_path('../application', __FILE__)

ActiveSupport::Deprecation.silenced = true                                                                                                                           

# Initialize the rails application                                                                                                                                       
MyApp::Application.initialize!

You can optionally wrap this in a block to only silence in production:

if ENV['RAILS_ENV'] == "production"
  ActiveSupport::Deprecation.silenced = true
end

Solution 4 - Ruby on-Rails

The best approach I have found is documented here. This is assuming you searched and found this question because you do have old-style plugins.

I went with the Make it not a gem at all part, because I needed to be able to turn plugins on/off during my capistrano deployment, based on what flavor of the app I was deploying. Before I used config.plugins to specify what plugin to use. With this approach I'm using a "require" on config.before_configuration instead.

Solution 5 - Ruby on-Rails

Just put following monkey patch into /lib/silence_heroku_warnings.rb

module Rails
  class Plugin < Engine

    alias :not_silenced_initialize :initialize

    def initialize(root)
      ActiveSupport::Deprecation.silence{ self.send :not_silenced_initialize, root }
    end

  end
end

and require it in config/application.rb just after requiring Rails:

require 'rails/all'
require File.expand_path('../../lib/silence_heroku_warnings', __FILE__)

All deprecations from 2.x-style plugins should be silenced. Other deprecations will show up.

Solution 6 - Ruby on-Rails

A cleaner way than just silencing warnings, here is what you can do.

For the logger injection you can try to use Heroku's new gem that Jared Beck mentioned in his reply above.

What we did instead is this:

You can inhibit Heroku from injecting its own plugins if you have a directory by the same name in your vendor/plugins folder. The folder just needs to exist. Heroku then will not inject its plugin, and if there is no code, Rails won't object with deprecation warnings. We just put a readme file explaining this into:

vendor/plugins/rails_log_stdout/readme.md

The purpose of Heroku's injected plugin for logging is to turn on Heroku-style logging (it requires logs to be sent to STDOUT, not to a file). To get that back, we did what I described in this answer. Tweaks to Heroku's default behaviors were needed for Unicorn anyway, so we got two birds in one stone.

Solution 7 - Ruby on-Rails

The new way of silencing deprecation notices is:

config.active_support.deprecation = :silence

in your config/environments/production.rb file.

Solution 8 - Ruby on-Rails

It looks like Heroku has finally addressed this.

   Injecting plugin 'rails_log_stdout'
   Injecting plugin 'rails3_serve_static_assets'
   Add 'rails_12factor' gem to your Gemfile to skip plugin injection

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionfearless_foolView Question on Stackoverflow
Solution 1 - Ruby on-RailsJared BeckView Answer on Stackoverflow
Solution 2 - Ruby on-RailskainView Answer on Stackoverflow
Solution 3 - Ruby on-RailsMichael HaleView Answer on Stackoverflow
Solution 4 - Ruby on-RailsyuяiView Answer on Stackoverflow
Solution 5 - Ruby on-RailsskaleeView Answer on Stackoverflow
Solution 6 - Ruby on-RailsWolfram ArnoldView Answer on Stackoverflow
Solution 7 - Ruby on-RailsJonathan MétillonView Answer on Stackoverflow
Solution 8 - Ruby on-RailsraidfiveView Answer on Stackoverflow