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.'
Related
I recently upgraded Rails to 5.2.0 and just noticed that substitute_values was removed from ActiveRecord::Relation
The thing is, I can't find any documentation about it, nor where it went or why it was removed. I don't think there was a deprecation warning, at least I couldn't find it. I did a search in the Rails Github and in SO, but couldn't find anything related with it
Does anyone know why it was removed or where can I read about it? I could just use the source code from 5.1.7, but I'd like to know where it was moved (if it was) so I can use it, or if it was removed for some specific reason
I am trying to understand some of the higher level functioning of Rails, using the Rails console. I run controller.class.superclass.superclass which gives ActionController::Base, controller.class.superclass.superclass.superclass which gives ActionController::Metal and controller.class.superclass.superclass.superclass.superclass gives AbstractController::Base.
I have found these in the API documentation.
http://api.rubyonrails.org/classes/AbstractController/Base.html
http://api.rubyonrails.org/classes/ActionController/Metal.html
[can only post two links]
I can add to these simply by declaring the classes again in the console, but is there a way to find the original Ruby code for these and to inspect and edit it in its original file(s)? Just in case I need to know the full contents of these for future.
You can also do:
bundle show <gem>
and that will show you where the gem is on your system. Editing in those files is not advised unless you know how to re-install gems.
You can see the Rails source code on Github:
https://github.com/rails/rails/tree/master/actionpack/lib/action_controller
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?
Trying my luck with the vote_fu rails plugin. The functionality looks like exactly what I need for a project of mine, but I have hit a roadblock. I have followed the github readme to the letter, installing it as a plugin.
I have put acts_as_voteable on my "Event" model and acts_as_voter on my User model.
In the console, when I try:
>> event.votes
or
>> user.votes
it successfully returns an empty array.
but when I try to do the following:
user.vote_for(event)
I get
"NoMethodError: undefined method `user_id' for #<Vote:0x7f5ed4355540>"
Any ideas? I'm probably just missing something obvious, but maybe something is missing from the plugin's readme.
Thanks.
[Update]
I created a blank application and the plugin works fine, so I think that this problem might be being caused by the use of the "desert" plugin, as my User class is split over two files. If I find the answer, I'll post it so that in the off chance someone else runs into this it may be some help.
Cheers.
Ok, I haven't found a definitive reason why this problem occurred, but I do have strong suspicions that it is due to the use of the "desert" plugin, as my User class is split over two files (the project is using the CommunityEngine plugin as a base),
Anyhow, I found a work around (something I should have tried before posting here). Instead of installing vote_fu as a plugin, I installed it as a gem. And now vote_fu seems to be humming along nicely.
So let that be a lesson to you all!
:-P
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