Notes posted by rxcfc
RSS feedNot really deprecated
This isn’t really deprecated, it’s just relocated to ActiveRecord::AttributeMethods#read_attribute
Alternative Way to Handle
This plugin may also help solve the problem from the model side.
http://github.com/rxcfc/multi_assignment_sanity
Set :use_route to nil to let Rails pick the best route
Imagine the following case. You have two landing pages, one generic one, and an account specific one. The urls are as follows:
map.landing 'landing', :controller => 'landing', :action => 'index' map.account_landing 'accounts/:account_id/landing', :controller => 'landing', :action => 'index'
Now imagine you want a path to the landing page, using the most specific route possible. If you have an account_id, use it, if not, skip it.
You could do
url_for(:controller => 'landing', :action => 'index', :account_id => current_account)
If current_account is set you’ll get “/accounts/:account_id/landing” if not, you’ll get “/landing”. However, that just looks ugly.
Enter :use_route => nil.
landing_path(:account_id => nil) # => '/landing' landing_path(:account_id => 1) # => '/landing?account_id=1' landing_path(:account_id => nil, :use_route => nil) # => '/landing' landing_path(:account_id => 1, :use_route => nil) # => '/accounts/1/landing'
Setting :use_route to nil, is equivalent to the earlier #url_for example.
More Information
More information can be found at ActionController::Verification::ClassMethods
:foreign_type option
I’m not sure if this has always been around but in 2.3, belongs_to takes a :foreign_type option on polymorphic associations. This behaves the same way as :foreign_key but for the type field.
Prompt vs. Select
According to the docs in form_options_helper.rb
:include_blank - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.
:prompt - set to true or a prompt string. When the select element doesn’t have a value yet, this prepends an option with a generic prompt – “Please select” – or the given prompt string.
The main difference is that if the select already has a value, then :prompt will not show whereas the :include_blank always will.
Validate Mixup
Looks like the docs from validate got mixed up here. Only the last example is actually relevant to validates_each.
More on deprecation
This is not deprecated. I think the docs are confused because the validate, validate_on_create, and validate_on_update methods are actually callbacks and not explicitly defined on their own. The correct usage is the same as in the docs above.