Deprecation policy • Rails 3.2.x • new deprecation warnings • Rails 4.0.0 • new features • new deprecation warnings • nothing is removed • easy upgrade • Rails 4.0.x • no new features • no new deprecation warnings • Rails 4.1: • new features • removes deprecated stuff 6
class ToySender attr_reader :kid_id, :toy_id def initialize(attr) @kid_id = attr[:kid_id] @toy_id = attr[:toy_id] end def run kid = Kid.find(@kid_id) toy = Toy.find(@toy_id) # toy.send_to(kid) end end # Then, add an instance of WishSender to Rails.queue. # A likely place for this code is in a controller: class KidsController < ApplicationController def send_toy Rails.queue << ToySender.new(params) flash[:notice] = "Toy queued to be sent!" redirect_to kids_url end end 4 4 17
# kids_controller.rb # don’t do this! can't be marshalled (serialized) in the # queue system WelcomeMailer.welcome(@kid).deliver # You should do WelcomeMailer.welcome(@kid.id).deliver # welcome_mailer.rb class WelcomeMailer < ActionMailer::Base def welcome(id) @kid = User.find(id) # prepare your mail end end 4 22
• doesn’t re-load JS and CSS • doesn’t re-compile • page instance is kept alive • only the body and title of the page are replaced 4 • response contains the full rendered page, so no bandwidth is saved 38
Turbolinks events page:fetch starting to fetch the target page (only called if loading fresh, not from cache). page:load fetched page is being retrieved fresh from the server page:restore fetched page is being retrieved from the 10-slot client-side cache page:change page has changed to the newly fetched version 41
• resource creation or replacement at some given URL • must send a complete representation of the resource • idempotent method (same request has always same result, think :updated_at) PUT 47
get '/toys/:id/purchase' => 'Toy#purchase' match '/toys/:id/purchase' => 'Toy#purchase', :via => :get match '/toys/:id/purchase' => 'Toy#purchase', :via => :any Rails4 forces a verb to be present on match routes Solution 53
# config/routes.rb Christmas::Application.routes.draw do ! resources :toys do ! ! resources :pictures ! end ! resources :kids do ! ! resources :pictures ! end ! resources :elves do ! ! resources :pictures ! end end Your routes are not DRY 3 55
# config/routes.rb Christmas::Application.routes.draw do ! concern :picturable do ! ! resources :pictures ! end resources [:toys, :kids, :elves], :concerns :picturable end Your routes are DRY 4 57
class Order < ActiveRecord::Base ! scope :past, where("orders.sent_on < ?", Time.current) end scope # DEPRECATION WARNING: Using #scope without passing a callable object is deprecated. 4 68
new form helpers collection_check_boxes(:toy, :category_ids, Category.all, :id, :name) do |b| b.label(:"data-value" => b.value) { b.check_box + b.text } end Customizable by a block 72