Where can one find a list of deprecated methods, APIs, etc, in order to upgrade from Rails 2.x to Rails 3?
The Rails 3 release notes have lots of good information:
Railties now deprecates:
RAILS_ROOT in favor of Rails.root,
RAILS_ENV in favor of Rails.env, and
RAILS_DEFAULT_LOGGER in favor of Rails.logger.
ActionController:
The cookie_verifier_secret has been deprecated and now instead it is assigned
through Rails.application.config.cookie_secret and moved into its own file:
config/initializers/cookie_verification_secret.rb.
filter_parameter_logging is deprecated in favor of
config.filter_parameters << :password.
ActiveRecord
named_scope in an Active Record class is deprecated and has been renamed to just scope.
save(false) is deprecated, in favor of save(:validate => false).
model.errors.on is deprecated in favor of model.errors[]
ActiveRecord::Base.colorize_logging and config.active_record.colorize_logging are deprecated in favor of Rails::LogSubscriber.colorize_logging or config.colorize_logging
ActionMailer
:charset, :content_type, :mime_version, :implicit_parts_order are all deprecated in favor of ActionMailer.default :key => value style declarations.
Mailer dynamic create_method_name and deliver_method_name are deprecated, just call method_name which now returns a Mail::Message object.
ActionMailer.deliver(message) is deprecated, just call message.deliver.
template_root is deprecated, pass options to a render call inside a proc from the format.mime_type method inside the mail generation block
The body method to define instance variables is deprecated (body {:ivar => value}), just declare instance variables in the method directly and they will be available in the view.
Mailers being in app/models is deprecated, use app/mailers instead.
I don't think you'll find an exhaustive list of depreciations because it really depends on what version of rails you are upgrading from. For instance, Rails 2.3.9 (just released) added additional depreciations over the previous release.
The Rails Upgrade Handbook (as mentioned above) is a great tool and contains 12 pages of depreciation warnings and how to fix them. I don't think they'll be published here because you should just drop the $9 and download the pdf to get the list. The included tutorials and other information makes it well worth it. It was for me.
If you don't want to pay for good information then just run the rails_upgrade plugin for your specific application. More information on how the plugin is on the rails upgrade plugin github page.
A good way of checking the specifics about an individual app would be to run the rails_upgrade plugin on it (you can find it at GitHub), it will output a list of deprecation notices and recommendations
Some useful info is also summarised in this blog post: http://www.simonecarletti.com/blog/2010/07/the-way-to-rails-3/
Additionally Railscasts has a bunch of movies on various changed aspects of the API. Go to Railscasts.com and browse the movies filed under the rails3 tag.
I found it to be a great value to buy http://www.railsupgradehandbook.com/
Another place to have deprecation's for active record is here (http://m.onkey.org/active-record-query-interface).
Reply if found useful.
How to disable colorize logging in ActiveRecord without Rails? Instead of keeping AR decoupled, independent ORM, it is now tightly bound to Rails framework.
Moving ActiveRecord::Base.colorize_logging to Rails::LogSubscriber.colorize_logging was just bad design and the wrong direction, wasn't was?
Related
I am upgrading an app to 4.0 and using ruby-2.2.5. I am down to a couple of Deprecation Warnings, which appear when I run >> bundle exec rake.
One of the warnings:
DEPRECATION WARNING: Model based mass assignment security has been extracted out of Rails into a gem.
Please use the new recommended protection model for params or add `protected_attributes` to your Gemfile to use the old one.
To disable this message remove the `whitelist_attributes` option from your `config/application.rb` file
and any `mass_assignment_sanitizer` options from your `config/environments/*.rb` files.
See http://guides.rubyonrails.org/security.html#mass-assignment for more information.
I understand what this about and I have gone through all my models looking for and removing 'attr_accessible'. I have gone through all my controllers and added a method for strong_params, which I call in my 'create' and 'update' actions. We are not using 'whitelist_attributes' or any 'mass_assignment_sanitizer' options. And, all my spec tests are passing.
My Questions is, Would this warning be just a standard output or would it be from rails seeing something I am not? Ideas?
Much appreciated
Try adding gem 'protected_attributes', '~>1.1.3' at your Gemfile, some people say that gem is unnecessary on Rails 4 but it fix the Deprecation, I not sure if is the best solution: https://github.com/rails/protected_attributes
I'm using this gem - https://github.com/paulelliott/fabrication and I've inherited some specs that contain the following
Fabricator(:tenant_user) do
user!
tenant!
end
For the life of me I can't find any documentation to detail what the bang is actually for... any ideas - or ideally a link to documentation?
Just got an answer from Paul who created the gem. Answering here as might be useful for anybody else.
'That is an old syntax that was deprecated with version 2.0.0. If you are on a newer version than that you can safely remove them.
If you're on an older version, those tell Fabrication to generate the model immediately instead of on 1st access. Without them it will wait until you actually call the field accessor to generate the associated model.'
I've tested this by running rails c both before and after git stash. On Rails 4.1 in Mavericks, after following the instructions to add the versions table and adding has_paper_trail to three models, whenever I run rails c I get
irb: warn: can't alias context from irb_context.
I've spent some time Googling without much luck, there's old threads talking about rspec, but I don't see how that's relevant since I'm not using it. Any ideas why this is happening?
RSpec used to polute provide Object top-level methods, e.g. describe, context, etc. Fortunately they've got rid of all the monkey patching in version 3, and now all these methods are namespaced under RSpec.
One can change this behaviour through the expose_dsl_globally config flag. For backwards compatibility, it defaults to true.
The warning shows up when you open the console because paper_trail automatically loads its rspec helpers when rspec is found. And it calls RSpec.configure before you have the chance to tweak your own configuration.
One possible solution would be paper_trail to disable the automatically loading and let users to load it themselves when they see fit. However, I am not aware of the internals of the library, so I can't guarantee this wouldn't break other things.
Best!
This is now fixed in papertrail 4.0.0, here's the commit.
I'm upgrading a rails 2 application to rails 3.2 and have come across what is described as an idiom.
person.tap |p| do
When I Googled for this and it appears to have been deprecated or moved. Is my understanding correct?
I ask because I can find a few examples of it on SO.
The tap method has been in Ruby since 1.8.7:
tap{|x|...} => obj
Yields x to the block, and then returns x. The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.
Note that 1.8.6 did not have Object#tap. Presumably, tap was in older versions of Rails (as a monkey patch on Object) but was added to Ruby itself in 1.8.7. Since 1.8.6 is rather ancient now, the Rails version was deprecated and, in more recent Rails releases, removed entirely.
Object#tap is still around so tap itself has not been deprecated, just the Rails monkey patched version has been removed.
The Object#tap monkey patch from ActiveSupport is deprecated because it has been part of Ruby since 1.9.0 and 1.8.7.
I looked in the Rails docs under inflector and found this message...
Module deprecated
This module is deprecated on the latest stable version of Rails. The last existing version (v2.1.0) is shown here.
There was no explanation or reference to any further detail.
I recalled seeing a Rails Trac website. I hunted that down and found that it too is deprecated. It referred me to Lighthouse.
I found some info there -- the Rails core team is not accepting patches for inflections.rb. But it didn't really explain the deprecation message. What is the story behind that?
You might take a look at this post for an explanation.
I'm looking at the Edge Rails source code for inflector.rb right now and I can't see anything to say that it's deprecated—where did you get that information from?
Patches aren't being accepted because they might break legacy code that's relying on incorrect inflections. You can add your own rules by accessing the singleton instance yielded by Inflector.inflections, as shown below:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'person', 'people'
inflect.uncountable 'rails'
end
Two separate issues at play. Inflections won't be patched to correct errors to protect legacy uses of incorrect inflections but more importantly inflections was moved into ActiveSupport as of 2.2.1
see 2.2.1 here versus pre 2.2.1 here