How to deal with vendor/plugins after upgrading to rails 3.2.1

后端 未结 4 884
故里飘歌
故里飘歌 2021-01-31 03:50

After upgrading to rails3.2.1,this warning occurs:

You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them

4条回答
  •  自闭症患者
    2021-01-31 04:38

    I just went through this and found that you just have to go through each plugin to check a few things:

    • Is it a gem on rubygems? If so, just stick it in your Gemfile and delete from vendor/plugins
    • If no gem is available, or the gem is old, take the folder in vendor/plugins and move it to lib/plugins

    One thing I ran across is that you then need to require all those plugins manually. Here is the initializer I created and placed in config/initializers/plugins.rb:

    Dir[Rails.root.join('lib', 'plugins', '*')].each do |plugin|
      next if File.basename(plugin) == 'initializers'
    
      lib = File.join(plugin, 'lib')
      $LOAD_PATH.unshift lib
    
      begin
        require File.join(plugin, 'init.rb')
      rescue LoadError
        begin
          require File.join(lib, File.basename(plugin) + '.rb')
        rescue LoadError
          require File.join(lib, File.basename(plugin).underscore + '.rb')
        end
      end
    
      initializer = File.join(File.dirname(plugin), 'initializers', File.basename(plugin) + '.rb')
      require initializer if File.exists?(initializer)
    end
    

    I also had the problem of initializers I needed for some of the plugins, so I moved those particular initializers into the lib/plugins/initializers folder. You have to name them the name of the plugin, so an initializer for the my_plugin plugin would have to be in the file lib/plugins/initializers/my_plugin.rb

    Hope this helps!

提交回复
热议问题