25
RAILS5 - TOP 5

Ruby on Rails 5: Top 5 Features

Embed Size (px)

Citation preview

Page 1: Ruby on Rails 5: Top 5 Features

RAILS5 - TOP 5

Page 2: Ruby on Rails 5: Top 5 Features

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

SYSTEM!"- DHH

Page 3: Ruby on Rails 5: Top 5 Features

5.NEW ACTIVE RECORD

ATTRIBUTES API

Page 4: Ruby on Rails 5: Top 5 Features

▸ 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)

Page 5: Ruby on Rails 5: Top 5 Features

4.RAILS COMMANDS

Page 6: Ruby on Rails 5: Top 5 Features

rails db:migrate

wat?

consistency: rails true one master command

Page 7: Ruby on Rails 5: Top 5 Features

3.API MODE

Page 8: Ruby on Rails 5: Top 5 Features

▸ integrated rails-api gemrails new foo --api

Page 9: Ruby on Rails 5: Top 5 Features

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

▸ Drop middlewares▸ and more...

Page 10: Ruby on Rails 5: Top 5 Features
Page 11: Ruby on Rails 5: Top 5 Features

STANDARD

Page 12: Ruby on Rails 5: Top 5 Features
Page 13: Ruby on Rails 5: Top 5 Features

API MODE

Page 14: Ruby on Rails 5: Top 5 Features

2.TURBOLINKS 3 5

Page 15: Ruby on Rails 5: Top 5 Features

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

Page 16: Ruby on Rails 5: Top 5 Features

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

Page 17: Ruby on Rails 5: Top 5 Features

▸ 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

Page 18: Ruby on Rails 5: Top 5 Features

1.ACTION CABLE

Page 19: Ruby on Rails 5: Top 5 Features

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

Page 20: Ruby on Rails 5: Top 5 Features

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)

Page 21: Ruby on Rails 5: Top 5 Features

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

Page 22: Ruby on Rails 5: Top 5 Features

MISC

Page 23: Ruby on Rails 5: Top 5 Features

ADDED

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

▸ test runner now reports failures inline

Page 24: Ruby on Rails 5: Top 5 Features

REMOVED

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

▸ ActiveRecord::Relation#uniq

Page 25: Ruby on Rails 5: Top 5 Features

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