📜 ⬆️ ⬇️

Rails 4.1 beta1 out

Not so long ago, on December 18, the next version of Rails was released. It's funny that there is a post , dated December 17th, and referring to an article from the future. From the next utility of the new version:



Installation


To ask about the new version of the rail, first you need to install it:

gem install rails -v 4.1.0.beta1 rails new rails_beta_app 

We are waiting for the installation of all dependencies and proceed to the study (by the way, if you are not satisfied with a bundle for too long, you can try a parallel bunlder ).
')

Spring


Spring is a gem that serves to speed up the loading of a Rails environment. After the initial load, your application is spinning somewhere in the background, greatly speeding up the loading of all commands that require loading of Rails: migration run, console launch and, of course, tests. The news was a great joy for me to introduce Spring into the rails themselves. Check for yourself: rails c; exit; rails c. Restart occurs almost instantly, which is good.

config / secrets.yml


Now you should keep secret keys in this file and access them using Rails.application.secrets . Example config / secrets.yml:

 development: secret_key_base: '3b7cd727ee24e8444053437c36cc66c3' some_api_key: 'SOMEKEY' 


Action Pack Variants


This functionality is useful if we need to render different views depending on different characteristics of the request. The release_notes gives the following example (I changed it a little bit):

 before_action :set_variants def show respond_to do |format| format.html.tablet # renders app/views/projects/show.html+tablet.erb format.html.phone { extra_setup; render ... } end end private def set_variants request.variant = :tablet if request.user_agent =~ /iPad/ request.variant = :phone if request.user_agent =~ /iPhone/ end 

This requires additional view files:

 app/views/projects/show.html.erb app/views/projects/show.html+tablet.erb app/views/projects/show.html+phone.erb 


Action Mailer Preview


Now you do not need to send a letter to yourself to see how it is formatted (or, perhaps, I sent it to myself alone, and all the cool lords used special tools long ago?). Suppose we have the following mailer:

 class NotifierPreview < ActionMailer::Preview def welcome Notifier.welcome(User.first) end end 

Then the preview will be available at localhost : 3000 / rails / mailers / notifier / welcome.

Active Record enums


The example laid out in release_notes makes my eye very happy:

 # Declare an enum attribute where the values map to integers in the database, but can be queried by name. class Conversation < ActiveRecord::Base enum status: [ :active, :archived ] end conversation.archived! conversation.active? # => false conversation.status # => "archived" Conversation.archived # => Relation for all archived Conversations 

A fly in the ointment: the link to the documentation is broken, but the topic is detailed in the article already mentioned above .

Conclusion


DHH inspires us to use Rails 4.1.0 beta by stating that Basecamp is already using this version. I think that I will launch my own small personal project on this version of the framework.

Source: https://habr.com/ru/post/207172/


All Articles