Ruby on Rails 5: Top 5 Features

Preview:

Citation preview

RAILS5 - TOP 5

PHILOSOPHY"WHAT MOTIVATES ME IS THAT ONE GUY""EMBRACE THE MONOLITH INTEGRATED

SYSTEM!"- DHH

5.NEW ACTIVE RECORD

ATTRIBUTES API

▸ Attributes don't need to be backed by DB column▸ Type detection override

attribute :price_in_cents, :integer

▸ Defaultsattribute :my_string, :string, default:

"new default"

▸ Custom Types# config/initializers/types.rb

ActiveRecord::Type.register(:money, MoneyType)

4.RAILS COMMANDS

rails db:migrate

wat?

consistency: rails true one master command

3.API MODE

▸ integrated rails-api gemrails new foo --api

▸ Include ActiveModelSerializers▸ Remove JQuery and Turbolinks gems▸ don't check for CSRF protection▸ Inherit from ActionController::API

▸ Drop middlewares▸ and more...

STANDARD

API MODE

2.TURBOLINKS 3 5

Most important: Partial replacement feature

Turbolinks will look for HTML5 custom attributes data-turbolinks-permanent and data-turbolinks-temporary to decide the replacement

strategy in our DOM.

Client side: Turbolinks#visit OR #replaceServer side: redirect_to/render

EXAMPLES

▸ Turbolinks.visit(url, { change: ['entries'] })

replace any DOM element with custom attribute data-turbolinks-temporary and any element with its id listed in change

▸ Turbolinks.visit(url)keep only DOM elements with custom attribute data-turbolinks-

permanent and replace everything

▸ Turbolinks.visit(url, { keep: ['flash'] })

keep only DOM elements with custom attribute data-turbolinks-permanent and any element with its id listed in keep, everything

else will be replaced▸ Turbolinks.visit(url, { flush: true })

replace everything

1.ACTION CABLE

ACTION CABLE == WEBSOCKETS IN RAILS▸ connection between a client and a server remains constant and

connected▸ either party can initiate a request or a message▸ direct interaction between browser and server

▸ must use multi threaded server

GLOSSARY

Cable: Connection between the user and the the app (one cable per session)

Channels: Layered over the cable for different use cases

Broadcaster: Backend sending stuff to user (Redis Pub-Sub, Postgres)

Demo:https://github.com/rails/actioncable-examples

MISC

ADDED

▸ Keyword arguments▸ ActiveRecord::Relation#or▸ Integer#negative?/positive?▸ Method#source_code▸ MySQL native JSON data type

▸ test runner now reports failures inline

REMOVED

▸ respond_to/respond_with => Renderer▸ render nothing: true

▸ ActiveRecord::Relation#uniq

SOURCEShttp://weblog.rubyonrails.org/2015/12/18/Rails-5-0-beta1/

http://edgeapi.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html

http://blog.michelada.io/whats-new-in-rails-5https://github.com/turbolinks/turbolinks

https://github.com/rails/rails/blob/8c752c7ac739d5a86d4136ab1e9d0142c4041e58/activerecord/lib/

active_record/attributes.rb