This document provides an overview and details about the upcoming Rails 2.0 release. It mentions that a preview release is coming before release candidates and the final release. It also notes that release 1.2.4 will include bug fixes and deprecation warnings to help upgrade existing apps. The rest of the document outlines new features and changes for Rails 2.0 across Action Pack, Active Record, and other areas.
3. Behold, behold, Rails 2.0 is almost here. But before we
can slap on the final stamp, we’re going to pass through
a couple of trial release phases. The first is this preview
release, which allows you to sample the goodies in their
almost finished state.
• 2.0
•
•
• by DHH
4. We might change a few things or add something else, but by and large, this
is how Rails 2.0 is going to look and feel. After this release have had a
chance to be tried out, we’re going to move to a release candidate or two
(or three, depending on how many we need). Then, the final release.
•
2.0
•
•
5. Before the release of 2.0, we’re also going to be putting
out 1.2.4, which will include a variety of bug fixes and
the last deprecation warnings to get you ready for
upgrading an existing application to 2.0 standards.
• 2.0 1.2.4
•
•
• 2.0
deprecation warning
6. Enough about process. Let me tell you a little bit about
what’s new in Rails 2.0:
• Rails 2.0
9. Action Pack: Multiview
# should go in config/initializers/mime_types.rb
Mime.register_alias quot;text/htmlquot;, :iphone
• respond_to class ApplicationController < ActionController::Base
before_filter :adjust_format_for_iphone
• show.rhtml private
show.html.erb def adjust_format_for_iphone
if request.env[quot;HTTP_USER_AGENTquot;] &&
request.env[quot;HTTP_USER_AGENTquot;][/(iPhone|iPod)/]
• request.format = :iphone
3.0 show.rhtml deprecated end
end
• show.csv.erb text/csv CSV end
class PostsController < ApplicationController
def index
respond_to do |format|
• − format.html # renders index.html.erb
format.iphone # renders index.iphone.erb
end
end
end
10. Action Pack: Record identification
# person is a Person object, which by convention will
# be mapped to person_url for lookup
redirect_to(person)
link_to(person.name, person)
form_for(person)
•
• URL
• URL
• :controller=>:user,:action=>:index
• form_to(person) person (PUT)
(POST) form action
11. Action Pack: HTTP Loving
class PostsController < ApplicationController
USER_NAME, PASSWORD = quot;dhhquot;, quot;secretquot;
before_filter :authenticate, :except => [ :index ]
• Basic ( ) def index
render :text => quot;Everyone can see me!quot;
end
• javascript_include_tag def edit
render :text => quot;I'm only accessible if you know
(:all,:cache=>true) the passwordquot;
end
private
public/javascripts/all.js def authenticate
authenticate_or_request_with_http_basic do |
user_name, password|
user_name == USER_NAME && password
== PASSWORD
end
end
end
13. Action Pack: Exception handling
class PostsController < ApplicationController
rescue_from User::NotAuthorized, :with => :deny_access
protected
def deny_access
...
end
end
• rescue_from
14. Action Pack: Miscellaneous
• atom RSS # index.atom.builder:
atom_feed do |feed|
feed.title(quot;My great blog!quot;)
feed.updated((@posts.first.created_at))
for post in @posts
• feed.entry(post) do |entry|
entry.title(post.title)
entry.content(post.body, :type => 'html')
• asset entry.author do |author|
author.name(quot;DHHquot;)
• end
end
• end
in_place_editor end
auto_complete_for Rails