Whats new in Rails 5
Ruby
2.2.2+
puma
- default dev server
- ActionCable development
ActionCable
- Websocket Support
- Channels
- Subscriber
API only Apps
- Rails API project
- Stripped Down Apps
rails new my-app-api --api
Command Router
- rake db:migrate => rails db:migrate
- rake and rails are not consistent
Attributes API
- attributeĀ class method
- Custom DataTypes
class MoneyType < ActiveRecord::Type::Integer
def type_cast(value)
if value.include?('$')
price_in_dollars = value.gsub(/\$/, '').to_f
price_in_dollars * 100
else
value.to_i
end
end
end
class StoreListing < ActiveRecord::Base
attribute :price_in_cents, MoneyType.new
end
store_listing = StoreListing.new(price_in_cents: '$10.00')
store_listing.price_in_cents # => 1000
ApplicationRecord
class ApplicationRecord < ActiveRecord::Base
self.abstract_class =true
include MyCustomErrorsModule
end
class Product < ApplicationRecord
end
ActionController::Renderer
MessagesController.render(partial: 'messages/message',
locals: { message: params[:message][:body] })
ActiveRecord#or
Post.where('id = 1').or(Post.where('id = 2'))
# => SELECT * FROM posts WHERE (id = 1) OR (id = 2)
TestRunner
- Single/Multiple tests
- Better Error messages
- Fail fast
- Colored output
- Minitest integration, and more
Snappier Development Mode
-
file system monitor using mtimes
-
evented file system monitor
-
listen gem
Versioned Migrations
class CreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
t.string :name
t.timestamps
end
end
end
# Rails 4
t.references :user, index: true, foreign_key: true
# Rails 5
t.references :user, foreign_key: true
Others
@vipulnsward
@BigBinary
deck
By Vipul Amler
deck
- 1,231