155

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?

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
  • 1
    Was even more preplexing for me as I DID have stuff there, but after removing it still go the error from Heroku! Great question, great answer – Phantomwhale May 17 '12 at 08:41

8 Answers8

203

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.

Jared Beck
  • 16,796
  • 9
  • 72
  • 97
  • 1
    Yep, I realize that all the warnings came from my Heroku scripts and logs. I'll assume that (a) it's the plugin injections and (b) that the Heroku team will fix this before it becomes an actual problem. – fearless_fool Jan 28 '12 at 04:20
  • Im a newbie and i am a little stuck on how i edit railties-3.2.0. Can you please help. – Benjamin Jan 30 '12 at 11:33
  • @vezu I recommend you don't start. This was something that used to be common before we started using bundler, but right now it's unlikely to work, and will probably just break stuff. – Matthew Rudy Jan 31 '12 at 08:21
  • @MatthewRudy do you have any suggestions. I email heroku yesterday but no luck. – Benjamin Jan 31 '12 at 08:39
  • 2
    I tried adding an initializer https://gist.github.com/1709421 but it doesnt work (I guess plugins are loaded earlier than app initializers). My suggestion is dont worry... its just noise. – Matthew Rudy Jan 31 '12 at 08:52
  • 3
    a year later... no change from heroku. – courtsimas Feb 21 '13 at 06:15
  • And rails 4.0 is almost upon us. From: http://weblog.rubyonrails.org/2013/2/25/Rails-4-0-beta1/ "Hot on the heels of the first production version of Ruby 2.0 comes the first beta version of Rails 4.0. The two form a great pair and are already running in production on a number of applications, including Basecamp Breeze. In fact, Ruby 2.0 is the preferred Ruby to use with Rails 4.0." Heroku is not having a good month however, so we'll see how much bandwidth they have for this issue. – Jamie Folsom Mar 20 '13 at 14:07
12

You can try

::ActiveSupport::Deprecation.silenced = true

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

kain
  • 5,510
  • 3
  • 27
  • 36
  • 5
    Ideally one would only suppress this particular warning, do you know if that's possible? – Vincent Mar 07 '12 at 03:14
  • if you do it in production.rb you should see the errors in development - if all else fails set the opposite in development.rb – iterion May 12 '12 at 06:39
  • 2
    Not suppressing the warnings for me – Leopd Jun 01 '12 at 17:49
  • 6
    One hack to suppress just this warning is to add the following to application.rb: `ActiveSupport::Deprecation.behavior = Proc.new { |msg, stack| $stderr.puts msg unless msg =~ /You have Rails 2.3-style plugins/ }` – Liron Yahdav Feb 05 '13 at 02:14
8

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
Michael Hale
  • 1,367
  • 13
  • 16
4

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.

yuяi
  • 2,617
  • 1
  • 23
  • 46
  • +1. I ended up using the [Matt Coneybeare gives you a nice walkthrough](http://matt.coneybeare.me/how-to-convert-simple-rails-23-style-plugins/) link (found in the page @yuri linked) to convert my simple rails 2.3 plugins to 3.2. I liked this solution because it didn't just silence the warnings, it actually fixes them. – Jeremiah Oct 08 '13 at 17:24
1

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.

skalee
  • 12,331
  • 6
  • 55
  • 57
1

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.

Community
  • 1
  • 1
Wolfram Arnold
  • 7,159
  • 5
  • 44
  • 64
  • Better add a blank file named `.gitkeep` to vendor/plugins/rails_log_stdout `.gitkeep` is a convention to keep an empty directory when using git. – tmaier Jul 25 '13 at 11:08
  • Fair enough, I prefer a little more verbosity as to why, that's why I liked the readme approach. You're right though that `.gitkeep` is a convention. – Wolfram Arnold Jul 26 '13 at 01:18
0

The new way of silencing deprecation notices is:

config.active_support.deprecation = :silence

in your config/environments/production.rb file.

Mab879
  • 608
  • 16
  • 33
0

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
raidfive
  • 6,603
  • 1
  • 35
  • 32