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

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.

Related

Rails 5 DEPRECATION WARNING: to_prepare is deprecated

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.

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

RJS Handler missing

I got a missing template error when I tried to achieve a task using RJS.
All I want is to execute an RJS file on ajax call. But I am getting the
following error.
ActionView::MissingTemplate (Missing template line_items/create,
application/create with {:handlers=>[:erb, :builder, :coffee],
:formats=>[:js, :html], :locale=>[:en, :en]}. Searched in:
* "<MY APP PATH>/app/views"
):
app/controllers/line_items_controller.rb:46:in `create'
But the create.js.rjs is present in the folder /views/line_items. You
can see the handlers miss .rjs extension. I think thats causing the
error.
If I change .rjs to .erb, it works and the content is executed as
javascript and thus I need to modify the RJS functions to Javascript to
return the contents of AJAX call.
Could you please explain how I can attain this using RJS? Please help.
Following is the versions of tools I use.
Ruby version 1.9.2 (i686-linux)
RubyGems version 1.8.10
Rack version 1.3
Rails version 3.1.0
JavaScript Runtime Node.js (V8)
Active Record version 3.1.0
Action Pack version 3.1.0
Active Resource version 3.1.0
Action Mailer version 3.1.0
Active Support version 3.1.0
Thanks in advance.
in order to use RJS with Rails 3.1 you have to use the prototype-rails gem
Make sure prototype-rails gem is in bundler's production group. If you put it in the assets group it will not register the RJS template handler.

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.