If you are not that familiar with Ruby on Rails, itâ€™s a web development framework thatâ€™s more than 10 years old now. Rails is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Experienced Rails developers also report that it makes web application development more fun.Â Today, Texo design -Â web app development servicesÂ Â will share somethings about Rails 5
Rails is opinionated software. It makes the assumption that there is a “best” way to do things, and it’s designed to encourage that way – and in some cases to discourage alternatives. If you learn “The Rails Way” you’ll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience.
Why You Should Be Excited About Rails 5?
After six months of polish, four betas, and two release candidates, Rails 5.0 is finally done! Itâ€™s the biggest release from the Ruby on Rails community since June 2013 and comes with an impressive range of features and changes.
Itâ€™s taken hundreds ofÂ contributorsÂ and thousands of commits to get here, but what a destination: Rails 5.0 is without a doubt the best, most complete version of Rails yet. Itâ€™s incredible that this community is still going so strong after so long.
The features of Rails 5.0 are as follows
1. Real-time data with Action Cable
+ ActionCable adds real-time features to Rails right out of the box. In the past, if you were thinking about which framework to use for a web app that relies on real-time features, then more often than not youâ€™d be advised to use NodeJS and SocketIO or a comparable framework. This is because these frameworks enable you to add a variety of real-time features to your app such as chat messages or notifications.
+ Well, not anymore! ActionCable leverages Websockets to keep open connections between the userâ€™s computer and the server. This way you can send data from your Rails server to all connected users and update whatever they see in their browser. The most obvious use case would be something like a chat app.
+ Want to learn more about it? Check outÂ the official example appÂ (it requires you to set it up locally).Â Basecamp, who make up the core team developing Rails, is the first and most popular web app using ActionCable for real-time communication among users.
2. Â Rails API only application
Another big change isÂ API mode. Traditionally, Rails is a framework for web apps that runs entirely in the web browser. It makes it very simple for you to build powerful and robust backend logic to interact with data and to integrate it with the frontend of your web app.
Nowadays, however, there are many use cases whereby the frontend and backend of an app are separated. Most commonly this would apply to smartphone or tablet apps. For example, you write your native app for Android or iOS but you want it to interact with a server to save data online. If this interaction is all you need your backend to do, you donâ€™t need any HTML pages. You simply need a solid backend your mobile app can connect to. Basically you don’t need ActionController::Base, Asset Pipeline, Views, Helpers etc…
With Rails 5 you can generate your Rails app in API mode which means it will be generated without any of the things you would normally need if you were to run your Rails app directly in the browser. This includes, for example, the â€œviewsâ€ and â€œassetsâ€ parts of Rails apps. You can then communicate with Rails through â€œRESTfulâ€ links and transfer data in simple JSON.
Command to create Rails API application:
rails new my_rails_api_app –api
If you want to Convert Existing Rails Application to API application
+ Open your config/application.rb file and add following line
config.api_only = trueÂ
class ApplicationController < ActionController::Base
# change this inherit from ActionController::API
class ApplicationController < ActionController::API
For many a Rails noob, having to figure out when to use â€œrakeâ€ and when to use â€œrailsâ€Â is a source of confusion. Now you donâ€™t need to switch context between the â€œrakeâ€Â and â€œrailsâ€Â commands. You can run all Rake tasks with the â€œrailsâ€ keyword.
The source of this issue in previous versions of Rails is the fact that some commands make sense to beÂ rails commands, such asÂ â€œrails serverâ€, and are not implemented as rake tasks,Â but the rest are implemented as rakeÂ tasks and are therefore called usingÂ â€œrakeâ€. If you implement your ownÂ rakeÂ tasks, you would have had to also call them usingÂ â€œrakeâ€.
In Rails 5, you can do everything with â€œrailsâ€ right now. For example, â€œrake db:migrateâ€ is now â€œrails db:migrateâ€. This may not look like much on the surface, but this will make the lives of beginners much simpler. Rails 5 will also add a â€œrestartâ€Â command that quickly restarts the application.
4. Rails 5 Only Support Ruby 2.2.2+
Rails 5 will only work with Ruby 2.2.2 or newer. In Ruby On Rails applications, we usually pass symbols all over the place, doing this open the possibility of DOS attacks when our memory is consumed by symbols that never get garbage collected.
Ruby 2.2.0 introduced changes in its garbage collector to be able to collect symbols.
Another reason for Rails 5 to support Ruby 2.2.2 is to take advantage of new Incremental GC which will help to reduce memory consumption by our Rails applications.
5. #or method in ActiveRecord::Relation
Finally ActiveRecord::Relation is getting #or method, this will allow us to write queries with ActiveRecord DSL as follows:
Book.where(‘author = 1’).or(Book.where(‘author = 3’))Â
\# => SELECT * FROM books WHERE (author = 1) OR (author = 3)
#or method accepts a second relation as a parameter that is combined with an or. #or can also accept a relation in a form of model scope.
6. #belongs_to is required by default
From now on every Rails application will have a new configuration option
config.active_record.belongs_to_required_by_default = true
It will trigger a validation error when trying to save a model where belongs_to associations are not present.Â We can disable this validation on each belongs_to definition, just passing an additional option optional: true as follows:
class Book < ActiveRecord::BaseÂ
Â Â belongs_to :author, optional: trueÂ
7.What else is new?
Rails 5 includes a whole number of big and small changes. Check out the full change logÂ hereÂ to see everything thatâ€™s new. But just to give you an idea of some of the other things to look out for, here are a few more to keep in mind:
+ Rails has a new logo and welcome screen when you first create your app.
+ Rails usesÂ PumaÂ as the default web server now instead of Webrick (some articles online are outdated and suggest you Â need a multi-threaded server such as Puma to run ActionCable. That used to be the case with early versions of ActionCable but thatâ€™s not necessary anymore. You can even use servers such asÂ unicorn).
+ Turbolinks 5 promises to load your pages much faster than before.
+ Use built-in helper methods like â€œon_weekdayâ€ or â€œon_weekendâ€ to check whether a date is a weekday or on a weekend.
Rails 5 is great news to both experienced and amateur programmers. It introduces some great new features such as ActionCable and API mode which offer us many more opportunities for building even more types of apps with Rails.
With Rails 5 you no longer have to make compromises, as you donâ€™t even have to think about different frameworks if youâ€™d like to have an API-only app or include real-time features. In a web where real-time data updates and speed are both increasingly important, the team behind Rails has made sure itâ€™s a solid choice for modern app development for years to come.
Texo Design is one of the renowned names inÂ rubyÂ web design melbourne. We are the team of well â€“ qualified and experienced staff as we deal with mobile apps, web development and social media campaign. We offer you the best tailor-made solution. Your success is our guarantee as we commit quality, professionalism and communication to our clients. These three pillars will help you in making your formal decision. We transform your ideas into reality with highly innovative technologies and experts mindset. Contact us +61 3 9995 0765 orÂ http://www.texodesign.com.au/Â for more information