📜 ⬆️ ⬇️

Ruby on Rails 3 - Final Release Notes

Table of contents

  1. Switch to Rails 3.0
    • Rails 3 requires Ruby 1.8.7+
    • Application object in Rails
    • script/* replaced by script/rails
    • Dependencies and config.gem
    • Transition process
  2. Creating a Rails 3.0 Application
    • Inclusion of gems
    • Life on the brink
  3. Architectural changes
    • Recharge Railties
    • All components of the Rails core are now independent.
    • Abstraction Active Model
    • Abstraction controllers
    • Arel Integration
    • Extract Mail
  4. Documentation
  5. Internationalization
  6. Railties
  7. Action pack
    • Abstract controller
    • Action controller
    • Action Dispatch
    • Action view
  8. Active Model
    • Abstraction ORM and interface with Action Pack
    • Validations
  9. Active record
    • Query interface
    • Enhancements
    • Patches and obsolete methods
  10. Active Resource
  11. Active support
  12. Action Mailers
  13. About creators


Ruby on Rails 3.0 is out! He will cook dinner for you and fill the washing machine with laundry. You will still wonder how you used to live without it. These are the best rails we have ever done!

Well, seriously speaking, it was a really great thing. With the arrival of the creators of Merb in the team, we implemented their best ideas, and, moreover, focused on the agnosticism of the framework, simplifying and accelerating the code, and also added a handful of new APIs. If you switch to Rails 3.0 from Merb'a 1.x, you will most likely be familiar with a lot. And you will definitely fall in love with Rails 3.0 by upgrading from any version 2.x.

But even if you don’t care about the internal cleaning of the code, you’ll still feel the full taste of Rails 3.0. We have prepared a whole bunch of new features and updated APIs. It's time to become a Rails developer. Here are the main changes:In addition to all this, we tried our best to isolate outdated APIs by supplying the corresponding components with special messages. Those. in order to upgrade to Rails 3.0 now, you do not need to rewrite all existing code to fit all the innovations.
These release notes cover only the major innovations, but not every bugfix or minor change. Rails 3.0 consists of about 4,000 commits from over 1,600 authors! If you need to know everything in detail, pay attention to the list of all commits .

1. Switch to Rails 3

As usual, when upgrading to a new version, it’s best to have your code covered as much as possible with tests. And, for a start, you'd better upgrade to 2.3.5 to make sure that your application is working properly even before switching to Rails 3.0.

1.1 Rails 3.0 requires Ruby 1.8.7+

Rails 3.0 requires Ruby 1.8.7 or higher. Support for previous versions has been officially discontinued, so we recommend that you upgrade to the new version of Ruby as soon as possible. In addition, Rails is compatible with Ruby version 1.9.2.

Note that in Ruby 1.8.7 p248 and p249 there are marshaling bugs that crash Rails 3.0. In Ruby Enterprise Edition, this has been fixed since version 1.8.7-2010.02. As for 1.9, Ruby 1.9.1 also cannot be used. in Rails 3.0, it causes segmentation errors (segfaults). So, if you want to use Rails 3.0 Ruby 1.9, jump immediately to 1.9.2.

1.2 Application Object

As part of working to support multiple Rails applications running in the same process, Rails 3.0 introduces a new concept that involves using the Application object. This object contains all of your application-specific configuration settings and, by its nature, is very similar to the contents of config / environment.rb from previous versions of Rails.

Now each Rails application has a special Application object. This object is defined in the config / application.rb file. If you need to update an existing application to a new version of Rails, you need to create this file manually, and copy the necessary information into it from config / environment.rb.

1.3 script/* replaced by script/rails

New script / rails now replaces all scripts in the corresponding folder. But you do not need to contact script / rails directly - just run the rails command from the root of the application, which, in the context of your application, executes the specified script. For example:
rails console # => ./script/console
rails g scaffold post title:string # => ./script/generate scaffold post title:string
The rails –help team will kindly provide the entire list of available options.

1.4 Dependencies and config.gem

The config.gem method went into non-existence in favor of the bundler 'a and Gemfile ' a (see “Turning on gems” below)

1.5 Transition Process

To automate and simplify the transition process, a special plugin was created - Rails Upgrade .

Just install the plugin and run $ rake rails:upgrade:check to find out which of the existing parts of your program need to be updated (with links to information about how and what to upgrade). Also in the plugin there is a task for generating a Gemfile based on existing calls in config.gem and a task for generating a new file with routes based on the old one. To download the plugin, simply do the following - $ script/plugin install git://github.com/rails/rails_upgrade.git .

You can learn by example how this all works, by clicking on the link Rails Upgrade now. Official Plugin .

On the other hand, if you need more help, you can always contact the people on the IRC channel or in the rubyonrails-talk mailing list, who probably do the same thing as you, and maybe even face the same problems. When you finally succeed - do not forget to write on your blog to share your experience with others!

More information - The Path to Rails 3: Approaching the upgrade .

2. Creating a new Rails application

The sequence at the moment looks like this:
$ gem install rails --version 3.0.0
$ rails myapp
$ cd myapp

2.1 Turning on gems

Rails now uses Gemfile to know which plugins are required to run your application. To read and work with this file, there is a new bundle gem, which puts all the necessary gems in the vendor directory, thereby isolating your application from system gems.

Additional information - Using bundler .

2.2 Life on the brink

Now, thanks to the bundler and Gemfile , in order to “freeze” your application, just run the special command bundle -ra - goodbye rake freeze ! ..

Well, if you use code from the Rails repository master branch, then to create an application, simply pass the - --dev flag:
$ rails myapp —edge

3. Architectural changes in Rails

The Rails architecture has undergone 6 major changes.

3.1 Recharging Railties

Railties have been updated to provide a robust API for writing plugins to any components of the framework. Generators and binders have also been completely rewritten, which gives developers the opportunity to move to an incomparably different level of elegance of their use.

3.2 All Rails core components are now independent.

Together with the merging of Merb and Rails, one of the main tasks was to get rid of the strong connection between the components of the Rails core. This goal has been achieved, and now all of the key Rails components use a single API that you can use to develop plug-ins.

This means that any plugin or replacement of any component of the kernel (using, for example, DataMapper or Sequel) has access to the same functionality as the kernel, with the possibility of its expansion and improvement.

More information - The Great Decoupling

3.3 Abstraction Active Model

Part of the work on the separation of components was the extraction of all bindings to the Active Record from the Action Pack. Now that this is completed, for any new ORM plugin, in order to work correctly with the Action Pack, all the Active Model interfaces need to be implemented.

Additional information - ActiveModel: let any Ruby object feel like ActiveRecord

3.4 Abstract controller

Another significant part in the work on the separation of components in the core was the creation of a base superclass isolated from HTTP in order to render templates and so on. Creating an Abstract Controller made it possible to significantly simplify the Action Controller and Action Mailer by extracting the code common to both in Abstract Controller.

More information - Rails Edge Architecture .

3.5 Arel Integration

Arel (or Active Relation) was taken as the foundation for Active Record and is henceforth one of the dependencies of a Rails application. Arel introduces a special SQL abstraction, thereby simplifying Active Record and providing a foundation for implementing relational functions in Active Record.

Additional information - Why I wrote Arel .

3.6 Retrieving Mail

From the day of its creation, Action Mailer was constantly hung up with dubious patches, pre-parsers and, in addition to combining with TMail, got agents to send and receive mail. In version 3.0, all the functionality related to e-mail was abstractly rendered in the Mail gem. This, again, reduced the amount of duplicate code and helped to separate Action Mailer from the email parser.

Additional information - New Action Mailer API in Rails 3 .

4. Documentation

Documentation for all API changes is in the process of being updated. In addition to this, the Rails Edge guides are also updated to reflect all the changes in Rails 3.0. However, guides.rubyonrails.org manuals will only correspond to the latest stable version (i.e. version 2.3.5, up to the final release 3.0).

More information - Rails Documentation Projects .

5. Internationalization

In Rails 3, a significant amount of work has been done on supporting internationalization. The latest version of the i18n heme is included and carries a significant optimization of the speed of work.More information - Rails 3 I18n changes .

6. Railties

Together with the separation of the main components within Rails, Railities have been thoroughly redesigned in order to facilitate the interaction between frameworks, engines and plugins, making it as painless and flexible as possible:At the beginning of the application generation, you can now use several new flags, including flags that allow you to skip the installation of components such as test-unit, Active Record, Prototype and Git. In addition, thanks to the new -dev flag, when installing the application, the Gemfile is taken from the current Rails repository. See rails –help for help.

Generators of various Railities have been given a huge amount of attention. In short:In addition, the generated view also received some improvements:Finally, improvements have touched and rake tasks:
Found obsolete:PLUGIN/rails/tasks and PLUGIN/tasks no longer loaded — all tasks must be in the PLUGIN/lib/tasks directory.

Additional information :

7. Action Pack

Action Pack has undergone significant internal and external changes.

7.1 Abstract Controller

From the Action Controller 'a to Abstract Controller , in the form of modules, the main parts were taken out, which can now be used to render templates, partial ' s, helper 's, internationalization, logging and any other part of the “request-response” cycle. Thanks to this abstraction, ActionMailer::Base now simply inherited from Abstract Controller 'a, being, as a wrapper, a wrapper over Rails DSL in the form of the Mail heme.

The introduction in the Abstract Controller all that was possible, has greatly simplified the Action Controller . However, it should be borne in mind that programmers will not be able to directly access Abstract Controller 's, this is not an API.

More information - Rails Edge Architecture .

7.2 Action Controller

Found obsolete:Additional Information:

7.3 Action Dispatch

Introduced in Rails 3.0, this new component is designed to greatly simplify routing.
It is important to remember that the outdated map commands are still in service, but with the advent of 3.1 they will disappear completely.
Found obsolete:
Additional Information:

7.4 Action View

7.4.1 Unobtrusive JavaScript

Helpers underwent significant revisions in the Action View: hooks for Unobtrusive JavaScript (UJS) were introduced, and the old inline-AJAX teams have sunk into oblivion. Thus, in Rails, you can now use any UJS driver to implement UJS hooks in helpers.

This means that all previously existing remote_ helpers remote_ been removed from the rails, and are now in the special Prototype Legacy Helper . Now, to access the UJS hooks, just pass :remote => true . So, for example:
form_for @post, :remote => true
will return:
form action="http://host.com" id="create-post" method="post" data-remote="true"

7.4.2 Block Helpers

form_for such as form_for or div_for , which insert content from the block now use <%= :
<%= form_for @post do |f| %>
<% end %>

Your own helpers of this type will return the string and not add the output manually to the output buffer.

Other helpers, such as cache and content_for , have remained intact.

7.4.3 Other changes

8 Active Model

Active Model is a new component of Rails 3.0. Now, any ORM library can interact with Rails - you just need to implement the Active Model interface, which is only an abstract layer.

8.1 ORM Abstraction and Action Pack Interface

Part of the work of disrupting the core components of Rails was to extract all the links in Active Record from the Action Pack. Now that this is complete, any ORM library need only implement the Active Model interfaces in order to simply access Active Record.

Additional information - Make Any Ruby Object Feel Like ActiveRecord


Active Record Active Model, ORM .

validates :attribute, options_hash .

options_hash , :: — ( ) .

-, ActiveModel. For example:
class TitleValidator < ActiveModel::EachValidator
Titles = ['Mr.', 'Mrs.', 'Dr.']

def validate_each(record, attribute, value)
unless Titles.include?(value)
record.errors[attribute] << 'must be a valid title'

class Person
include ActiveModel::Validations

attr_accessor :title
validates :title, :presence => true, :title => true

Active Record:
class Person < ActiveRecord::Base
validates :title, :presence => true, :title => true

Additional information :

9. Active Record

Active Record Rails 3 : Active Model, Arel, . API Rails 2.x , Rails 3.1 .


Active Record, Arel, relation . API Rails 3.1, Rails 3.2. , , :Additional information :



, Active Record :, :It should be noted that the last few months being developed so-called. State Machine is not included in Rails 3.0.

10. Active Resourse

Active Resourse was also extracted in Active Model, which made it easy to use Active Resourse objects in the Action Pack.
Found obsolete:

11. Active Support

Active Support, Active Support , - . , Rails .
, Ruby 1.8.7 Ruby 1.9:REXML Active Support, Ruby 1.8.7 . Active Support , , .


12. Action Mailer

TMail Mail , Action Mailer API. , Action Mailer . , Action Mailer Abstract Controller'a, Mail gem. Action Mailer.
Additional information :


, Rails 3. !

Ps. , .
PPS. maratk !

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

All Articles