Merb and Rails from the decision of the merger began, after a year of hard work has finally released Beta version of Rights. Rails3 most important figure is the overall architect Yehuda Katz, and the entire Rails core turned to several turn, complete face-lift.
Why? I thought, DHH start when developing Rails, Ruby community is also less developed, so many things to create their own (even the prototype is to Rails and made), in order to reach a very easy to set up with the rapid development of the ideal package stacks may have to do what function the sea, coupled with limited resources, resulting in the Rails core actually tied very tight, basically an entire packet to you. To modify the expansion of it, often have to monkeypatch about. On the other hand, on how the Ruby program is a good program, did not start so many people wish to make clear, for example, Rails core filled with alias_method_chain, this matter is now considered relatively poor form.
Rails3 different times, Ruby community up. We have standard Rack interface, we have different ORM even NoSQL repository, we have different JS Libary, we have different test methods RSpec , we also have many ready-made do not need to create a new library. Rails3 basically get rid of such a close rewritten version, but reconstruction of the way to achieve this inclusive goal: to clarify the API again, completely modular, low-coupling components, greatly enhance the performance and so on. Specifically, there are several outcomes:
Use Ruby 1.8.7 or the Ruby 1.9
1.9 times finally arrived to review my speech last year slide .
Original config.gem replaced with a new Bundler used to manage all the library, use the new Gemfiles format, the original issue of multi-functional limited config.gem sucks. Now, we really do not rely on the system can be completely gems. Can refer to this model Bundle me some Rails Bundle of use
As the full import Rack relationship, now Route is a way to Rack middleware, is implemented on the Rack-Mount . Route first sight is the new API changes, and can refer to this Revamped 3 Routes in Rails , but this is not the most important place, the most powerful is that its parameters: to access the endpoint is rack ends, The main # home is MainController.action (: home) the short (yes!! Rails3 each Controller actions are all a standard Rack app!! cool!!), you can see Yehuda's implementation instructions . Since it is a Rack endpoint, we can give it access other Rack app, such as Sinatra, this article demonstrates how to pick 3 Routing with Rack Rails , really super easy ah. We can anticipate that there will be more interesting Rack middlewares can be combined with Rails.
In addition, we can do directly in the Routes layer directly redirect and render template, you can see real-Yehuda, explained: Generic Actions in Rails 3 , is basically a simple Rack middleware.
The new Active Model
In order to achieve the goal of convergence of different ORM, Rails3 the ActiveModel the original ActiveRecord functionality out of the individual to become Module, such as callbacks, validations, serialization, observing, dirty tracking etc.. Any Class that they meet the definition of several ActiveModel API, plus you need to include Module, you can take with Rails3 together. See ActiveModel: Make Any Ruby Object Feel Like ActiveRecord.
Validation of them new API, please refer validates: rails_3,: awesome => true
That ActiveRecord itself? Introduced ARel The SQL generation tool (why Arel?), A substantial use of "method chain" series with usage, so that each operation turned into a scope.
ActiveRecord and therefore have a new API: Active Record Query Interface 3.0
Responder brought respond_with, the wording can be simplified controller, use reference Cleaner RESTful Controllers w / respond_with , Default RESTful Rendering and Three reasons to love ActionController:: Responder This is a few. This tool is very interesting, before I even wrote a plugin respond_methods to make Rails 2.x support this feature.
In addition, the new Render implementation allows you to easily extend it a Render Options in Rails 3 demonstrates how to make your own render: pdf.
Several major changes:
1. Using Erubis implementation
2. Default XSS protection open, do not forget to add h longer escape the. Please refer to SafeBuffers and Rails 3.0 for more details
4. Helpers default output format is HTML 5.
Mail this tool replaced the first floor, and can refer to this description. Then benefit from the Controller of the reconstruction results, the new Controller inherits from ActionMailer finally and with a AbstractController, to increase the number of functional ActionMailer also greatly DRY up.
The new API, please refer to New ActionMailer API in Rails 3.0
Changed its position on the final app / mailers, and on the app / models, it is not people confuse ah.
ActiveSupport there before nasty is that if you just want to use one of several features, very easy to get to know what in the end to require something, and had to load them altogether in order to Insurance. New Rails3 this thing figured out, you can only load the part you want.
Rails Application object
In order for a Process can run multiple Rails app, Rails3 use a Rails Application object to represent an entire Application of all the settings, so therefore you have the config / environment.rb features, almost all moved to config / application.rb the. In addition, Rack standard config.ru file was added to the root directory, it is particularly note the name of your Application, which will interact with other use of the name of the Application, the default is the directory name.
The new Rails Module
Was removed a few constants, RAILS_ROOT to switch Rails.root, RAILS_ENV to use Rails.env, RAILS_DEFAULT_LOGGER to use Rails.logger, etc. For details, see this The Rails Module (in Rails 3) . Into the benefits of the object, we do not need to do this kind of thing a string operations.
The new rails command
The original script / * command all removed, are replaced with the rails. For example, script / console into a rails console (can be abbreviated into the rails c), script / generate into rails generate (can be abbreviated into the rails g), script / server into a rails server (can be abbreviated into the rails s). Use rails-help can see a complete description.
Rails3 reading data is very large, the official Rails 3.0: Release Notes are required reading. If you cut into the direction from the upgrade, you can use the official upgrade Plugin Rails-Upgrade is now an official plugin , it can help you 1. checks need to upgrade the place 2. produce Gemfile 3. create new routes.rb. Please with this The Path to Rails 3: Approaching the upgrade to take. But ah, now, or do not upgrade in the Production environment better, after all, a lot of miles Plugin not keep up (you can see Is Your Plugin Ready For Rails 3? and Rails Wiki which Plugins OK with finishing up).
If it is much easier from the start, you can see The Path to Rails 3: Greenfielding new apps with the Rails 3 beta this. Is recommended if you have time, you can now begin play read.
If you want to learn more about Rails framework, there are a few articles to look at:
* The Path to Rails 3: Introduction (be the simplest one, can see)
* Rails 3 Beta is Out - A Retrospective
* Rails 3: The Great Decoupling
* Rails Edge Architecture
* Rails and Merb Merge: The Anniversary (Part 1 of 6)
* Rails and Merb Merge: Performance (Part 2 of 6)
* Rails and Merb Merge: Plugin API (Part 3 of 6)
* Merge Rails and Merb: Rails Core (Part 4 of 6)
Suddenly discovered this in more detail, you can refer to ~