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

Rails 5 Changes.

Rails 5 Changes.

Rails 5 has made lot of minor changes to make developers life easier . some of them are listed in this presentation.
This was used when i gave an introduction of rails 5 in local ruby meet-up in Mumbai, India.
This is a collaborative list of all the data available already on web.
Specially from https://speakerdeck.com/claudiob/rails-5-features.

Pritesh Jain

June 26, 2016
Tweet

More Decks by Pritesh Jain

Other Decks in Programming

Transcript

  1. 1.  ActionCable 2.  Rails Json Api 3.  Sprockets 4 4. 

    Turbolinks 5 5.  Ruby 2.2+ 6.  And much more.. And I am going to talk about much more part .. :-D
  2. ž Active Job has been merged into Rails! ž Active Job is

    a framework for declaring jobs and making them run on a variety of queueing backends. Ref: http://edgeguides.rubyonrails.org/active_job_basics.html
  3. ž Seamlessly integrates WebSockets with the rest of your Rails application.

    It allows for real-time features to be written in Ruby in the same style and form as the rest of your Rails application, while still being performant and scalable. Ref: http://edgeguides.rubyonrails.org/action_cable_overview.html
  4. ž API only apps •  rails new api_app --api ž Load Limited

    set of middlewares ž JBuilder ActiveModel::Serializer ž While upgrading •  config.api_only = true Ref: http://edgeguides.rubyonrails.org/api_app.html#why-use-rails-for-json-apis- questionmark
  5. ž Partial template name does no more have to be a

    valid Ruby identifier Ref: https://github.com/rails/rails/commit/da9038e
  6. ž Why are migrations versioned in Rails 5? •  backward compatibility

    •  To adopt major version too. Ref: http://blog.bigbinary.com/2016/03/01/migrations-are-versioned-in-rails-5.html https://github.com/rails/rails/pull/21538
  7. ž  rails g migration AddTokenToUsers token:token ž  Added ActiveRecord::SecureToken in

    order to encapsulate generation of unique tokens for attributes in a model using SecureRandom Ref: https://github.com/rails/rails/pull/18217
  8. Post.where('id = 1').or(Post.where('id = 2')) # => SELECT * FROM

    posts WHERE (id = 1) OR (id = 2) Added the #or method on ActiveRecord::Relation, allowing use of the OR operator to combine WHERE or HAVING clauses
  9. http_cache_forever do render "It will literally set the cache control

    headers for forever. Make sure that you are using it with static content only." end Ref: http://blog.bigbinary.com/2016/03/04/rails-5-adds-http-cache-forever.html
  10. Don’t convert empty arrays to nils when deep array params

    Ref: https://github.com/rails/rails/pull/16924
  11. ž  In Rails 4, if we return false from any

    of the before_ filters, the entire callback chain used to stop. ž  No longer stops in Rails 5. ž  Explicitly throw(:abort) to stop it. •  Caveat: For older apps getting upgraded to Rails 5, the callback will still halt with returning false. as this is a breaking change. •  ActiveSupport.halt_callback_chains_on_return_false Ref: https://github.com/rails/rails/pull/17227
  12. ž  Ludicrous Speed #21057 https://github.com/ rails/rails/pull/21057 ž  This change shaves

    off 34,299 objects and 3,457,318 bytes (3.29 MiB) allocated on every request. This is a 29% decrease in objects and a 23% decrease in memory allocated per reques ž  11.9 % speed improvement
  13. ž  https://github.com/rails/rails/pull/21155 •  Speed up code and avoid unnecessary MatchData

    objects ž  https://github.com/rails/rails/pull/20946 •  Freeze string literals when not mutated. •  Shaving off 1 second of execution time for every 220 requests.
  14. ž  Rails reloads all code in development when something changes.

    For that it has to do a complete walkthrough of all files. ž  gem 'listen’ ž  Caveat: •  On Linux and Mac OS X there are no additional dependencies, but some are required for *BSD and for Windows.