Rails 5 DEPRECATION WARNING: to_prepare is deprecated - ruby-on-rails-5

When running rspec tests, I am getting the following deprecation warning
DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1 (use ActiveSupport::Reloader.to_prepare instead) (called from <top (required)> at /Users/Chris/Sites/golf_mentor/config/environment.rb:5)
Line 5 of my environment.rb is just
Rails.application.initialize!
How do I fix the code so this deprecation warning does not occur?

That message for sure is generated because a gem is using that deprecated method.
Maybe with rspec -b you could have more insight about what gem is and update that gem (in the best case that the warning was already solved).
If that doesn't work, another option could be to update your gems until find which one is causing the warning.
The last option is just ignore the warning because is not going to cause you problems until you update your app to rails 5.1 and when that time comes you will know which gem is because it will throw an exception.

Related

Getting rid of DEPRECATION WARNING: env is deprecated and will be removed from Rails 5.0.

While migrating to Rails 5.0.0.beta1 I discovered lots of deprecation warning :
DEPRECATION WARNING: env is deprecated and will be removed from Rails 5.0. (called from XXX at YYY)
I've tried to get rid of that and try to find an alternative but found nothing in the actionpack changelog.
Any ideas ?
ok, so it seems that env method has been deprecated in ActionPack by this commit.
so from now on we should user request.env instead of env in our controllers and helpers.

Problems with "rake test"

I have one problem with the command "rake test" that I don't know how to resolve. When I execute this command show me:
DEPRECATION WARNING: primary_key_name is deprecated and will be removed from Rails 3.2 (use foreign_key instead). (called from foreign_key at /home/guilhermec/.rvm/gems/ruby-1.9.2-p290#iba-jornais/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/association_matcher.rb:194)
What can I do to resolve it ?
This warning stems from a deprecated method in a gem. If you want you can:
file a issue on the project page
fork the gem and replace the method
ignore it
edit: this seems to be fixed in shoulda-matchers since 9 months

warning in installation in fedena

I got following warning while installing fedena , how do I fix it
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Spec::Rake::SpecTask#task called at C:/Fedena/lib/tasks/rspe
c.rake:28:in `initialize'
I had recently installed Fedena. The command "bundle exec rake db:create" worked for me! Glad to provide more info if needed!
1. Go to rakefile
change require 'rake/rdoctask'
to require 'rdoc/task'
2. Go to Gemfile
add gem 'rdoc'
3. run Bundle

as_paperclip_bridge initialization error in rails3

I'm trying to use both of PaperClip and ActiveScaffold with help of as_paperclip_bridge in a rails3.0.5 project.
However, following initialization error is occurred when I launch the project.
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
C:/Users/ken/Documents/NetBeansProjects/fcheck/vendor/plugins/as_paperclip_bridge/init.rb:10: undefined method bridge' for ActiveScaffold:Module (NoMethodError)
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/plugin.rb:81
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:ininstance_exec'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in run'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:50:inrun_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:inrun_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:134:in initialize!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:insend'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in method_missing'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config/environment.rb:7
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:inrequire'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in new_constants_in'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:3
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:ininstance_eval'
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in initialize'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:1:innew'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:1
The code in as_paperclip_bridge\init.rb is attempting to call a module method 'ActiveScaffold.bridge' but it coun't be found.
Even though, same code is working without error in rails2.3.8 project.
We can see a big difference of rails initialization code between version 2 and 3.
On rails 2.3.8, plugins are loaded in 'load_plugins' method which is called after 'load_gems' method in initializer.rb. However, rails3 doesn't have initializer.rb and the loading process seems to be totally different.
I also have tried to remove AS gem and install both of AS plugin with as_paperclip_bridge plugin. But, the error haven't disappeared.
Could someone explain why the error is occurring?!
Anyway, I really hope to get any solution or workaround.
Thanks,
Kenichi
Self reply.
I had realized that as_paperclip_bridge was not required for latest ActiveScaffold implementation. (It's including the bridge)
Please make sure to install ImageMagick and RMagick gem to use PaperClip for image files. Or, you may also think 'as_paperclip_bridge should be there'
Thank you,
Kenichi

Rails - migrating from 3.0 to 3.1

I wanted to help out a open source project by migrating from 3 to 3.1
But I have never had to migrate a large project before so I am looking for some advise ?
this is the project - https://github.com/locomotivecms/engine
Thanks, Alex
here it is an "almost working" locomotivecms code, migrated on rails 3.1:
https://github.com/lgs/engine/tree/rails-3.1
... it is not ready for pull request,
infact it miss to replace /images/ whith /assets/ in all the relative path ...,
anyway it start and stay up (despite many "DEPRECATION WARNING"), on rails 3.1 server:
lsoave#ubuntu:~/rails/github/engine$ rails s
DEPRECATION WARNING: config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
=> Booting WEBrick
=> Rails 3.1.0.rc4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-06-22 01:54:34] INFO WEBrick 1.3.1
[2011-06-22 01:54:34] INFO ruby 1.9.2 (2010-12-25) [i686-linux]
[2011-06-22 01:54:34] INFO WEBrick::HTTPServer#start: pid=2948 port=3000
Rails console works fine as well :
lsoave#ubuntu:~/rails/github/engine$ rails c
DEPRECATION WARNING: config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
Loading development environment (Rails 3.1.0.rc4)
ruby-1.9.2-p136 :001 >
This is the guide I followed during my try :
http://davidjrice.co.uk/2011/05/25/how-to-upgrade-a-rails-application-to-version-3-1-0.html
UPDATE:
"Cannot modify SafeBuffer in place" error resolved
UPDATE jun 23 11:
resolved "ArgumentError (wrong number of arguments (4 for 3))" adding options param (the fourth) to set_session into lib/locomotive/session_store.rb b/lib/locomotive/session_store.rb
Thanks to Nicholas Hubbard previous answer.
Reposting from GitHub:
It looks like the new sessions in 3.1 require 4 params:
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb Line 61
def set_session(env, sid, session_data, options)
The store in locomotive only takes three:
https://github.com/lgs/engine/blob/rails-3.1/lib/locomotive/session_store.rb Line 31
def set_session(env, sid, session_data)
Looks like options are being passed also that we are not expecting.