Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's New in Rails 4.2

What's New in Rails 4.2

A brief overview of new features in Ruby on Rails 4.2

Presented at Austin on Rails on October 28, 2014

Anthony Lewis

October 28, 2014

More Decks by Anthony Lewis

Other Decks in Programming


  1. What's New In Rails 4.2 Anthony Lewis

  2. @AnthonyLewis Best known for my hit single “Candy Rain”

  3. @AnthonyLewis Also, wrote a book…

  4. Rails 4.2 • Active Job • Action Mailer • Global

    ID • Adequate Record • Web Console • Other Changes • Installation • Release Notes
  5. Active Job • Framework for background processing using Resque, Delayed

    Job, Sidekiq, etc. • Switch between background runners without having to rewrite jobs • If no adapter is specified, jobs run immediately
  6. Configuration • Add your preferred background processing library to your

    application’s Gemfile: • Update Rails configuration: gem 'sidekiq' config.active_job.queue_adapter = :sidekiq
  7. Creating Jobs • Use the Rails generator to create a

    new job: $ bin/rail g job process_video create app/jobs/process_video_job.rb
  8. Job Source • The newly created job: class ProcessVideoJob <

    ActiveJob::Base queue_as :default def perform(*args) # Do something later end end
  9. Enqueue Job • Enqueue with or without a time: #

    Run next ProcessVideo.perform_later(@video) # Run tomorrow ProcessVideo.set(wait: 1.day) .perform_later(@video)
  10. Error Handling • Catch exceptions with a block: class ProcessVideoJob

    < ActiveJob::Base ... rescue_from(Exception) do |e| # do something with exception end end
  11. Action Mailer • ActionMailer now uses ActiveJob to send email

    • Call deliver_now to send a message inline # Send inline UserMailer.success_email(@user) .deliver_now
  12. Action Mailer • Call deliver_later to enqueue delivery • Accepts

    :wait, :wait_until, and :queue options # Enqueue and send later UserMailer.success_email(@user) .deliver_later
  13. Global ID • A unique identifier for a model instance

    • ActiveJob uses Global ID to automatically serialize and deserialize objects irb> video.to_global_id.to_s => "gid://appname/Video/1"
  14. Adequate Record • Optimizations to Active Record that make the

    find, find_by_*, and find_by methods up to 2x faster • Caches the static parts of the SQL query User.find(1) # Caches the static part: # SELECT * FROM users WHERE id = ? User.find(2) # Uses the cache, executes faster
  15. Web Console • Debugging tool for your Rails app •

    Automatically opens a Rails console on exceptions • Can also be opened with the console view helper <%= console %>
  16. None
  17. Other Changes • Previously deprecated functionality has been removed •

    Check for deprecation warnings before updating • The respond_with / class-level respond_to methods have been moved to the responders gem • The default host for rails server is now localhost instead of • If you dev in a virtual machine this will bite you
  18. Other Changes • The default log level for production is

    now :debug, just like development and test • The HTML sanitizer has been replaced with a new version. • Some sanitized output might change • Foreign key support (finally) • And more…
  19. Release Notes • The work-in-progress release notes are online: http://edgeguides.rubyonrails.org/4_2_release_notes.html

  20. Installation # In your terminal: $ gem install rails --pre

    # In your Gemfile: gem 'rails', '~> 4.2.0.beta2'
  21. Questions?

  22. Thank You!