Tuesday, October 5, 2010

Rails 3.0: It's ready!

CCH : As posted by DHH on Riding Rails

Posted by David August 29, 2010 @ 06:28 PM

Rails 3.0 has been underway for a good two years, so it’s with immense pleasure that we can declare it’s finally here. We’ve brought the work of more than 1,600 contributors together to make everything better, faster, cleaner, and more beautiful.
This third generation of Rails has seen thousands of commits, so picking what to highlight was always going to be tough and incomplete. But here’s a choice selection of major changes for Rails 3:
New Active Record query engine
Active Record has adopted the ARel query engine to make scopes and queries more consistent and composable. This makes it much easier to build complex queries over several iterations. We also delay the actual execution of the query until it’s needed. Here’s a simple example:

users = User.where(:name => "david").limit(20)
users = users.where("age > 29")

# SELECT * FROM users 
# WHERE name = "david" AND age > 29 
# ORDER BY name
# LIMIT 20
users.order(:name).each { |user| puts user.name }
Read more in new Active Record guide and watch the Dive into Rails 3: ARel video.
New router for Action Controller
When we switched to a REST-based approach for controllers in Rails 2, we patched on the syntax to the existing router while we were waiting to see if the experiment panned out.
It did and for Rails 3 we’ve gone back and revamped the syntax completely to favor the REST style with less noise and more flexibility:

resources :people do
  resource :avatar

  collection do
    get :winners, :losers
  end
end

# /sd34fgh/rooms
scope ':token', :token => /\w{5,5}/ do
  resources :rooms
end

# /descriptions
# /pl/descriptions
# /en/descriptions
scope '(:locale)', :locale => /en|pl/ do
  resources :descriptions
  root :to => 'projects#index'
end
Read more in the new routing guide.
New Action Mailer
Action Mailer was born with a split-personality of half model, half controller. In Rails 3, we’ve made the choice to make it all controller. This means that the feel and functionality will be much closer to Action Controller and in fact they now share a bunch of underlying code. Here’s a taste of what it looks like now:

class Notifier < ActionMailer::Base
  default :from =>
    "Highrise " 

  def new_project(digest, project, person)
    @digest, @project, @person = digest, project, person

    attachments['digest.pdf'] = digest.to_pdf
    attachments['logo.jpg']   = File.read(project.logo_path)

    mail(
      :subject => "Your digest for #{project.name}",
      :to => person.email_address_with_name
    ) do |format|
      format.text { render :text => "Something texty" }
      format.html { render :text => "Something texty" }
    end
  end
end
The new Action Mailer is built on top of the new Mail gem as well. Say goodbye to TMail headaches.
Read more in new Action Mailer guide.
Manage dependencies with Bundler
Managing all the dependencies of a Rails application has long been a hassle of patchworks. We had config.gem, Capistrano externals, custom rake setup tasks, and other incomplete solutions.
Bundler cleans all that up and allows you to specify the libraries, frameworks, and plugins that your application depends on. All Rails 3 applications are born with a Gemfile to control it all. See more on the Bundler site.
XSS protection by default
The internet is a scary place and Rails 3 is watching out for you by default. We’ve had CRSF protection with form signing for a while and SQL-injection protection since the beginning, but Rails 3 ups the anté with XSS protection as well (hat tip to Django for convincing us).
See the Railscast on XSS video and the Dive into Rails 3: Cross-site scripting video for more.
Say goodbye to encoding issues
If you browse the Internet with any frequency, you will likely encounter the � character. This problem is extremely pervasive, and is caused by mixing and matching content with different encodings.
In a system like Rails, content comes from the database, your templates, your source files, and from the user. Ruby 1.9 gives us the raw tools to eliminate these problems, and in combination with Rails 3, � should be a thing of the past in Rails applications. Never struggle with corrupted data pasted by a user from Microsoft Word again!
Active Model: Validations, callbacks, etc for all models
We’ve extracted quite a bit of commonly requested Active Record components into the new Active Model framework. This allows an ORM like Mongoid to use Active Record’s validations, callbacks, serialization, and i18n support.
Additionally, in the rewrite of Action Controller, we removed any direct references to Active Record, defining a clean, simple API that ORMs can implement. If you use an API-compliant ORM (like DataMapper, Sequel, or Mongoid), you will be able to use features like form_for, link_to and redirect_to with objects from those ORMs without any additional work.
Official plugin APIs
We also rewrote Railties with the express goal of using the new plugin API for all Rails frameworks like Active Record and Action Mailer. This means that Rails plugins like the ones for DataMapper and RSpec have access to all of the integration as the built-in support for Active Record and Test::Unit.
The new Railtie API makes it possible to modify the built-in generators, add rake tasks, configure default Rails options, and specify code to run as early, or as late as you need. Rails plugins like Devise were able to add much better integration in the Rails 3 version of their plugin. Expect to see a lot more of that in the months ahead.
Rewritten internals
We rewrote the internals of Action Pack and Railties, making them much more flexible and easier to extend. Instead of a single monolithic ActionController::Base, Rails 3 exposes a number of modules, each with defined APIs, that you can mix and match to create special-purpose controllers for your own use. Both Action Mailer in Rails and the Cells project make heavy use of this new functionality.
You can also take a look a this blog post by Yehuda (from last year) to see how the new architecture makes it easy to implement Django-style generic actions in Rails by leveraging Rack and ActionController::Metal.
The Rails generator system is got a revamp as well. Instead of monolithic generators that know about all of the Rails frameworks, each generator calls a series of hooks, such as :test_framework and :orm, that plugins can register handlers for. This means that generating a scaffold when using rSpec, DataMapper and Haml will generate a scaffold customized for those plugins.
Agnosticism with jQuery, rSpec, and Data Mapper
The rewritten internals and the new plugin APIs have brought true agnosticism to Rails 3 for all components of the framework. Prefer DataMapper to Active Record? No problem. Want to use jQuery instead of Prototype? Go ahead. Eager to test with rSpec instead of test/unit? You got it.
It’s never been easier to Have It Your Way™ with Rails 3. And at the same time, we’ve made that happen without making using the excellent default stack any more complicated.
Documentation
Rails 3 has had a long development cycle and while that might have lead to some impatience, it has also given book and tutorial authors a chance to catch up and be ready. There’s a wealth of great Rails 3 documentation available already and more is coming shortly.
The Agile Web Development with Rails 4th Ed book is almost ready and there are plenty more books coming. Check out all the new guides, the new official videos, new Railscasts, and a new tutorial. See the recent recap of documentation sources for more.
Installation
gem install rails --version 3.0.0. We also have a Rails v3.0.0 tag and a 3-0-stable branch.
Rails 3.0 has been designed to work with Ruby 1.8.7, Ruby 1.9.2, and JRuby 1.5.2+.
Gratitude and next steps
I’m personally incredibly proud of this release. I’ve been working on Rails for more than 7 years and the quality of the framework we have today is just astounding. This is only possible as a community effort and Rails 3 has seen so many incredible developers step up and help make this our best release ever (wink). Many thanks to all of you.
We’ll continue to develop Rails 3.0 with fixes and tweaks via the stable branch and Rails 3.1 is already cooking on master.
UPDATE: We’re raising money for Charity:Water in the name of Rails 3.0. Please donate and help us bring clean water to 5,000 people in the name of the Rails community.

Ruby on Rails 2.39 Released on 4th September 2010

We’ve released Ruby on Rails 2.3.9 (gem and git tag) to extend the 2.3.8 bridge a few steps closer to Rails 3 and Ruby 1.9. If your app runs on Rails 2.3.9 without deprecation warnings, you’re looking good for an upgrade to Rails 3.

Deprecations

  • Changes i18n named-interpolation syntax from the deprecated Hello {{name}} to the 1.9-native Hello %{name}.
  • Replaces Kernel#returning with Object#tap which is native to Ruby 1.8.7.
  • Renames Array#random_element to Array#sample which is native to Ruby 1.9.
  • Renames config.load_paths and .load_once_paths to the more accurate config.autoload_paths and .autoload_once_paths.
Along with these deprecations come a broad array of bugfixes and minor tweaks. Read the commit log for the full story.
Onward to 3.1!

Thursday, June 10, 2010

Ruby on Rails Version 2.3.8 released on 25th May 2010

CCH : An update from Riding Rails

The 2.3.7 release slipped out the door too hastily. Fixing compatibility with the rails_xss plugin inadvertently forced everyone to use it. Facepalm.

I apologize for wasting a chunk of your day on installing what ought to have been a patch-level update only to find it breaks your app. That’s well out of line with our stable release process and it’s my fault for stepping out of it. I got caught up in a sky-is-falling response to a 2.3.6 bug that affected a handful of users and responded with a fix that exposed a new flaw to nearly all users, despite testing and sanity checking.

Thanks for all your feedback today. We hear you, and yes, a thousand times yes. Every stable release, including point releases, deserves the same methodical drumbeat on its march from git stable to to .pre gem to final gem. Expect no less.

Now, on to the gem-cutting: Rails 2.3.8 is available now, bringing us back to stable ground.

Ruby on Rails Version 2.3.7 released on 23rd May 2010

CCH : Update from Riding Rails

With the 2.3.6 release hot out of the oven, Nathan Weizenbaum began updating HAML to support it.

He uncovered a couple of bugs in the HTML-safety changes backported from Rails 3, so we’re cutting a 2.3.7 release to fix them.

If you use the rails_xss plugin for automatic HTML escaping, you should upgrade to Rails 2.3.7 and the latest rails_xss plugin.

If you don’t use the rails_xss plugin yet, now’s the time to start. It’s baked in to Rails 3.
Update: fixing compatibility with the rails_xss plugin broke HTML-safety for apps that don’t use rails_xss. We’re sorry, all: HTML-safety is meant to be opt-in! The fix is available now in 2.3.8.pre1 and will be released shortly.

Tuesday, June 8, 2010

Ruby on Rails Version 2.3.6 released on 23rd May 2010

CCH : Ruby on Rails Version 2.3.6 released on 23rd May 2010

We’ve released Ruby on Rails 2.3.6: six months of bug fixes, a handful of new features, and a strong bridge to Rails 3.
We deprecated some obscure and ancient features in Rails 2.3.6 so we could cut them entirely from Rails 3. If your app runs on Rails 2.3.6 without deprecation warnings, you’re in good shape for a smooth sail onward.
This slow-cooked dish is brought to you some 87 committers from our all-volunteer kitchen.
Now, let’s open the goodie bag!

Action Pack

  • Upgrade Rack from 1.0.1 to 1.1.0.
  • XSS prevention: update to match Rails 3 and move to the official plugin at http://github.com/rails/rails_xss.
  • Cookies: convenient cookie jar add-ons to set permanent or signed cookies, or both at once: cookies.permanent.signed[:remember_me] = current_user.id. Read more.
  • Flash: promote alert and notice, the most common flash keys in many apps, to self.alert = '...' and self.notice = '...'. Add redirect_to url, :alert => '...' and :notice => '...'. Read more.
  • i18n: localize the label helper.

Active Record

  • Namespacing: support optional table name prefixes on modules by defining self.table_name_prefix. Read more.
  • Destroy uses optimistic locking.
  • Counter cache: use Post.reset_counters(1234, :comments) to count the number of comments for post 1234 and reset its comments_count cache.
  • PostgreSQL: always use standard-conforming strings, if supported.
  • MySQL: add index length support. Read more.
  • MySQL: add_ and change_column support column positioning using :first => true and :after => :other_column.

Active Support

  • Upgrade i18n from 1.3.3 to 1.3.7.
  • Upgrade TZInfo from 0.3.12 to 0.3.16.
  • Multibyte: speed up string verification and cleaning.
  • JSON: use YAJL for JSON decoding, if available. gem install yajl-ruby
  • Testing: add assert_blank and assert_present. Read more.
  • Core: backport Object#singleton_class from Ruby 1.8.8, deprecating our Object#metaclass.
  • Core: add Object#presence that returns the object if it’s #present? otherwise returns nil. Example: region = params[:state].presence || params[:country].presence || 'US'
  • Core: add Enumerable#exclude? to match include?.
  • Core: rename Array#rand to Array#random_element to avoid collision with Kernel#rand.
  • Core: rename Date# and Time#last_(month|year) to #prev_(month|year) for Ruby 1.9 forward compatibility.

Active Resource

  • JSON: set ActiveResource::Base.include_root_in_json = true to serialize as a hash of model name -> attributes instead of a bare attributes hash. Defaults to false.

Action Mailer

  • Upgrade TMail from 1.2.3 to 1.2.7.

Railties

  • Silence RubyGems 1.3.6 deprecation warnings.

Saturday, February 13, 2010

Rails 3 Beta Release on 5th February 2010


You thought we were never going to get to this day, didn’t you? Ye of little faith. Because here is the first real, public release of Rails 3.0 in the form of a beta package that we’ve toiled long and hard over.
It’s surely not perfect yet, but we were out of blockers on the list, so here we go. Please give it a run around the block, try to update some old applications, try to start some new ones, and report back all the issues you find.
I’m really proud of this moment, actually. We’ve had more than 250 people help with the release and we’ve been through almost 4,000 commits since 2.3 to get here. Yet still the new version feels lighter, more agile, and easier to understand. It’s a great day to be a Rails developer.
There’s plenty to get excited about here. A few of the headliner features are:
  • Brand new router with an emphasis on RESTful declarations
  • New Action Mailer API modelled after Action Controller (now without the agonizing pain of sending multipart messages!)
  • New Active Record chainable query language built on top of relational algebra
  • Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)
  • Explicit dependency management with Bundler
But please take a look at the full release notes and enjoy the latest!
To install:
gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre

Welcome to Rails.. Rails... Rails !

In 1995, I started the popular Clipper...Clipper... Clipper website (no blogs then) which was very popular and linked by virtually every Clipper-related site. When I switched to Windows via Delphi in 1997, I started the Delphi... Delphi... Delphi site. In June 2007, I discovered Ruby on Rails and no prize for guessing what I am gonna name this blog. which I started on 2nd October 2007.

As at 10th June 2010, we have 13,364 unique visitors from more than 84 countries such as Angola, Andorra, Argentina, Australia, Austria, Algeria,Barbados, Bosnia and Herzogovina, Belgium, Brazil, Bulgaria, Bangladesh, Belarus, Bolivia, Chile, Cambodia, Cape Vede, Canada, China, Colombia, Costa Rica, Croatia, Cyprus, Czech Republic, Denmark, Egypt, Estonia, Finland, France, Guadeloupe, Guatemala, Germany, Greece, Hong Kong, Hungary, India, Indonesia, Ireland, Israel, Italy, Japan, Kenya, Korea, Lithuania, Latvia, Malaysia, Mexico, Macao, Netherlands, Nepal, Norway, New Zealand, Oman, Panama, Peru, Poland, Portugal,Paraguay , Philippines, Romania, Russian Federation, Saudi Arabia, Singapore, Spain, Slovakia, Slovenia, Serbia, South Korea, Slovenia, South Africa, Spain, Switzerland, Sri Lanka, Sweden, Taiwan, Thailand, Turkey, United Arab Emirates, Ukraine, USA, UK, Venezuela, Vietnam

CCH
10th June 2010, 19:42