#318 Upgrading to Rails 3.2
Jan 23, 2012 | 9 minutes | Rails 3.2
Rails 3.2 sports many new features including automatic explain queries, tagged logging, key-value store in Active Record, improved migration generator and more. Learn all about these new features in this episode.
Resources
Gemfile
gem 'rails', '3.2.0'
group :assets do
gem 'sass-rails', " ~> 3.2.3"
gem 'coffee-rails', "~> 3.2.1"
gem 'uglifier', '>= 1.0.3'
end
gem 'rails', '3.2.0' group :assets do gem 'sass-rails', " ~> 3.2.3" gem 'coffee-rails', "~> 3.2.1" gem 'uglifier', '>= 1.0.3' end
terminal
bundle update
rails g model product_variation product_id:integer:index name 'price:decimal{7,2}'
rails g migration add_properties_to_product_variations properties:text
rake db:migrate
echo -d postgresql -T > ~/.railsrc
bundle update
rails g model product_variation product_id:integer:index name 'price:decimal{7,2}'
rails g migration add_properties_to_product_variations properties:text
rake db:migrate
echo -d postgresql -T > ~/.railsrc
rails console
puts Product.order(:name).explain
ActiveRecord::Base.silence_auto_explain { Product.order(:name) }
Product.pluck(:name)
Product.pluck(:id)
Product.select(:name).uniq
Product.where(name: "Foo").first_or_create!
Product.where(name: "Foo").first_or_create!(price: 5)
"Product".safe_constantize
p = ProductVariation.new(color: 'blue', size: 3)
p.color
p.size
p.properties[:color]
puts Product.order(:name).explain ActiveRecord::Base.silence_auto_explain { Product.order(:name) } Product.pluck(:name) Product.pluck(:id) Product.select(:name).uniq Product.where(name: "Foo").first_or_create! Product.where(name: "Foo").first_or_create!(price: 5) "Product".safe_constantize p = ProductVariation.new(color: 'blue', size: 3) p.color p.size p.properties[:color]
config/environments/development.rb
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.log_tags = [:uuid, :remote_ip]
# Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) config.active_record.auto_explain_threshold_in_seconds = 0.5 config.log_tags = [:uuid, :remote_ip]
config/environments/test.rb
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict
models/product_variation.rb
store :properties, accessors: [:color, :size]
store :properties, accessors: [:color, :size]

