What’s new in Rails 5
Rails 5 is out now. Current version of rails 5 – 5.1.0.rc1 was released on March 20, 2017. Without any doubts it is the best version yet. So do you want to know what are the new features of rails 5? Let’s see some of the star features or we can say major changes of it.
In development mode, Action Cable runs in-process with the rest of your app. So, the default development server is changed to Puma from Webrick.
The command for creating a Rails API is :
rails new new_app –api
This will create a stripped-down Rails application with a smaller set of middleware. It will change the parent for ApplicationController from ActionController:Base to ActionController::API.
The following line is added to the config/application.rb file.
class Application < Rails::Application
Config.api_only = true
After these, you won’t have views, helpers and assets. But you can use JBuilder, Active Model Serializers.
Attributes API is one of the major additions to the Rails 5. It allows you to define custom attributes on a model or override existing attributes. For example, you can create a MoneyType attribute type, and define how it gets stored as a price_in_cents field in the database.
In file app/models/product.rb:
class Product < ApplicationRecord
attribute :price_in_cents, MoneyType.new
class MoneyType < ActiveRecord::Type::Integer
# convert values like ‘$10.00’ to 1000
product = Product.new(price_in_cents: ‘$10.00’)
product.price_in_cents #=> 1000
Traditional web apps may take more time due to full page reloads. Rails 5 came up with its solution by just reloading the bare minimum content area. Turbolinks doesn’t refresh the entire page. Turbolinks 3 allows you to retain most of your page and selectively update certain regions through partials.
These are some major changes Rails 5 introduced. Few of them might have been missed by me but I tried to cover up most of them. Try something new with Rails 5 in your next project!
posted on February 20, 2017
posted on February 8, 2017
posted on February 25, 2017
posted on April 18, 2017
posted on April 10, 2017