Today, the first release candidate of RoR 3.1 was released, to which an official blog wrote an overview article about the key innovations in the upcoming version. To acquaint you with innovations, I translate with explanatory comments for those who have not heard anything about it. Further in the text italics my notes.As I (DHH - translator's comment) and promised on RailsConf, we are finally ready to release Rails 3.1: Release Candidate. This is a fantastically exciting release. It has two new killer features and a lot more simply amazing improvements. To start killer features:
Asset pipeline
The key feature in 3.1 will be the asset pipeline running
Sprockets 2.0 . It allows much more organically to organize CSS and JavaScript, including in plug-ins and engines (Engines). You can listen to the detailed description at
my speech at RailsConf . By default, asset pipelines comes with
SCSS for style sheets and
CoffeeScript for JavaScript. A large amount of documentation on the way.
Asset Pipeline is a generic term for a new concept of working with the client part of an application. The general meaning of it is that now how the controllers, views and models are generated for your scaffolds, JS and CSS will also be created. This allows you to achieve a more convenient architecture and scatter dozens of files from public / javascript into modules. Rails themselves will take care of assembling all your client files into one and caching.')
HTTP Streaming
This innovation will allow the browser to start downloading style sheets and javascript before the browser has finished generating the answer. The result is a noticeable increase in page speed. This is just an option that requires support from a web server, but the popular combination of nginx + unicorn is already ready to provide this. RailsCasts has a
video about it, you can also see the documentation
here .
The basic principle of operation is that the cached header (everything before </ head> for example) is given immediately after the request, the browser starts downloading the scripts and css specified in it, while the server makes requests to the database, etc.jQuery is now defaulted
We made
jQuery the default JavaScript framework that comes with Rails, but rolling back to Prototype is just as easy. They are installed using Bundler in the jquery-rails and prototype-rails gems. Just select the desired Gemfile and it just earns.
Other goodies:
- Reversible migrations : DRY migrations that know themselves how to reverse. Cleaner, prettier, easier. Yes, you no longer need self.up and self.down, everything has become even more declarative.
- Mountable engines : Engines can now have their own space of routs and helpers (as well as new assets, documentation will be available soon). Here you can read their background (the truth about assets there is already outdated).
- Entity map (Identity map) : Not enabled by default due to important issues that still need to be cleaned up. However, if you can come to terms with them, then this will be a great way to reduce the number of calls being called. Faster means better! Previously, when you made two identical requests in action, the second request was taken from the cache, but the objects were created anew . Now with an entity map, one entry in the database = one object in the front-end. In addition, which helps to avoid unnecessary requests, it also simplifies debugging (changes made to the record in one place, but not yet saved, now affect the entire answer).
- Prepared expressions (Prepared statements) : ActiveRecord now uses cached prepared expressions that give a big performance boost in PostreSQL and on complex queries in MySQL. Instead of forming a request and sending it to the database each time Rails makes a request once, and then uses its special token (substituting the necessary data) for making a similar one. Gives a performance gain of 20-30% on simple queries and a 10-fold (!) Increase in queries per second on complex queries.
- Rack :: Cache is enabled by default : Makes it possible to use HTTP caching with conditional retrieval (Conditional Get) as a replacement for page by page caching (which we will soon issue as a plugin and remove from delivery). Rack :: Cache is an engine that uses HTTP headers (Expires, Cache-Control, Last-Modified, ETag) for cache design. Conditional acquisition — by getting a record and checking that the last access time is later than the change time, we give 304. Replace page-by-page caching, which is almost unprofitable if you have small, always dynamic page pieces (for example, the current user’s panel when displaying almost static data ).
- Turn - a new conclusion for Test :: Unit in Ruby 1.9: The display when passing tests is much nicer and clearer. Available for new applications in Ruby 1.9.
- ForceSSL: Now, maintaining application security is easier than never. Available by application and controller. One line in the config - and the specified routes with http will be redirected to https.
- Role -based mass-assignment : attr_protected now takes a role as a parameter, so with admin / non-admin, etc. Now work is much easier. Looks like in 3.1 you can forget about CanCan. The thing is very interesting, I advise you to look about it in RailsCasts at the link below.
- has_secure_password : simple embedding of password protection on BCrypt. Now there is no forgiveness for those who do not raise their own authentication scheme. Generally speaking, it gives nothing but a password. Those who need password recovery, blocking, registration confirmation, etc., will still have to use Devise (which Rack-based will not receive profit from the innovation).
- Custom serializers: Serialize objects in JSON, or whatever you like. If earlier I used serialize in the YAML database, now I can choose the method for storing objects by myself by specifying the load and dump methods.
You can also view a
huge list of changes , as well as a small
video overview on RailsCasts.
If you are creating a new application, it is better to use Ruby 1.9.2. Rails will support 1.8.x up to 4.0, but only for compatibility. Ruby 1.9.x is the trend. Join and enjoy the sudden burst of speed.
You can install Rails 3.1 RC as always with
gem install rails --pre
. Enjoy the release and
send bugs to github . The final version is expected in a couple of weeks, if everything goes like clockwork.