RailsConf Europe: David Heinemeier Hansson
Posted by Nick Sieger Tue, 18 Sep 2007 08:14:00 GMT
Rebel With a Cause
Rails is no longer the James Dean character, looking outward, trying to convince you of something. It’s no longer about a rebellion or a revolution. Instead, Rails is settling in as a passionate, inward-looking craftsperson.
After the rebellion, settle in and enjoy the results of your work. David hasn’t been working directly on Rails too much, instead he’s been enjoying it.
And it’s not about David anymore. It’s about You (cue the Time Person of the Year cover). David wants Rails to be more friendly to newcomers.
Report #12: Verified Patches. Encouraging the community to approve patches, rather than limiting the decisions to the core. Opening up Rails. (Also, unfortunately looking a little scarce at the moment. Update: turns out it’s empty because patches are quickly applied, not because there aren’t any submitted!)
David screened the original Rails movie -- showing Apache setup, manually creating databases and tables. He quickly lost patience for it.
Compare to the current state of the art, with everything down to the routes and migrations gets created for you, lowering the barrier to entry (example: a new rake task db:create:all
).
Rails 2.0 is largely about continual improvement and removing the cruft:
- Cookie-based session store as the default
- Routing:
map.root
- Removing the dynamic
scaffold :posts
feature map.namespace
andscript/generate controller admin::posts
*.html.erb
files with the MIME type and renderer baked into the filename, since the two are now mutually exclusive.- Automatically named partials with
render :partial => @posts
resolving to_post.html.erb
- Namespacing and named routes:
mop.namespace :admin do |admin|
admin.resources :posts
end
# ...
link_to 'Show', [:admin, post]
- HTTP authentication
class Admin::PostsController < ApplicationController
before_filter :ensure_administrator
# ...
private
def ensure_administrator
authenticate_or_request_with_http_basic("Blog Admin") do |user,pass|
username == "dhh" && password == "123"
end
end
end
- Custom layouts for specific user agents (say, oh, the iPhone). Views can also be rendered, e.g.,
index.iphone.erb
.
class ApplicationController < ActionController::Base
before_filter :adjust_format_for_iphone
def adjust_format_for_iphone
if request.env["HTTP_USER_AGENT"][/iPhone/]
request.format = :iphone
end
end
end
# initializer
Mime::Type.register "application/x-iphone", :iphone
# In a controller method
respond_to do |format|
format.iphone { render :text => "Hello iPhone", :content => Mime::HTML }
end
atom_feed_helper
, a new plugin -- builder for Atom specified inindex.atom.builder
<%= yield :head %>
,content_for :head { auto_discovery_link(:atom, formatted_posts_url)}
- Debugger -- allows you to be lazy and leave your
breakpoint
s in your production code, not that you’d actually want to do that. Dumps you into irb where you can inspect variables, etc. but you can also drop down another level to see the call hierarchy, etc.
So when will we see Rails 2.0? The preview release is coming, hopefully before conference end.
Verified patch report is empty because all the patches are applied very soon they become verified.
So, an empty report is not scarse, it’s just a sign of success!
Even better! Thanks for the clarification.
I’m liking the custom layouts, such as the iPhone example. With the announcement of the UK iPhone launch today I can’t wait to work on an optimised version of my Rails app.
Why optimize just for the IPhone? There are a lot of phones/devices out there. Why not make it so it’ll work on all devices that supports a certain level of html+css etc?
Opera Mobile and Opera Mini can display any page on almost any device. Why not try your application on that today? http://www.operamini.com/beta/simulator/
@Michael
That is because in the Rails world, it is uncool to use anything not made by Apple (unless Apple is not in that market). You should know this by now.
David just used iPhone as an example. Rails doesn’t have “optimization” done for iPhone speicifically. The main idea is, you can set the fomat using request.format= based on any request env params. For example, it can be used to do some specific rendering for r’tard IE in just the same way.
Another thing he missed was, when you set content_type => Mime::HTML, rails will use layout.html.erb as layout.