RAILS 5......
Rails 5 is on his way moving faster than we can guess. Rails conference have finished up. It was the largest official gathering of the year, attended by top Rails talent, companies and project representatives from all over the world. The 2015 edition of RailsConf was presented by Ruby Central, Inc., and held in Atlanta, GA from 21 to 23rd of April.
Following are some cool features of Rails 5 :-
1. ActiveRecord::Base#where.or
In previous versions of rails in order to use "OR" condition we had to construct the query manually as:
but now in rails 5 we can write like:
Post.where('id = 1').or(Post.where('id = 2'))
# => SELECT * FROM posts WHERE (id = 1) OR (id = 2)
2. belongs_to is default to required: true
Almost every belongs_to declaration seems to be a required association. It's rare that you allow your foreign key to be nil.
However, if you don't want this feature `belongs_to` association is not required, you could use the `optional: true` option:
3. has_secure_token in Active Record
Now no need to write special methods to generate Security Token. Security token is most important part of authentication and authorization during API requests.
Just one line is sufficient to generate unique Hexadecimal security token.
class User < ActiveRecord::Base
has_secure_token :token1, :token2, key_length: 30
end
user = User.new
user.save
user.token1 # => "973acd04bc627d6a0e31200b74e2236"
user.token2 # => "e2426a93718d1817a43abbaa8508223"
user.regenerate_token1! # => true
user.regenerate_token2! # => true
4. Render From Anywhere
Earlier we had to use gems like render_anywhere to render any views outside of controller — for example in Rake tasks or background jobs.
In Rails 5 you’ll have the ability to render your views from anywhere:
ApplicationController.render _render_options_
5. No more Rake command
In rails 5 rake command is accessible by rails.
Rails 4: rake db:migrate
Rails 5: rails db:migrate
Rails 5: rails db:migrate
The reason for this change is that currently it's not very logical which command has to go through rake and which command should go through rails. When you're working with rails for a longer time it becomes second nature, but only because you remember it. For a newcomer, this is a big problem and makes learning rails confusing.
6. Ruby 2.2.1 support only
Rails will only support Ruby 2.2.1 and up. Since it wants to be able to leverage all the speed improvements in the newer ruby versions
.
They skipped version 2.2.0 since it has a segfault bug source.
No comments:
Post a comment