Welcome to Giant Robots Smashing Into Other Giant Robots — a weblog about development, business, design and technology — written by thoughtbot.
rails 2 point oh jesus
So I’ve been gradually getting my feet wet with the new Rails 2.0 release.
Then I ran into the changes to ActionController::Resources#resource:
A singular name is given to map.resource. The default controller name is still taken from the plural name.
This means that if you have the following in your routes.rb
1 2 3 4 5 6 |
ActionController::Routing::Routes.draw do |map| map.resource :session end |
Rails is going to look for a SessionsController not a SessionController. So even though you’re using the singular version, #resource, Rails is expecting a plural controller name.
This is terrible. I just recently discovered the beauty of #resource and singleton controllers and now Rails 2.0 assumes that all singleton resources map to plural named controllers.
One of my favorite idioms was to use a singular resource for allowing users to edit their password (I always put password editing on a page separate from editing the rest of a user’s info, try keeping password changes along side your other user info changes and see how ugly your code gets. A separate controller cleans things up nice and allows you stay with CRUD naming for all your actions).
1 2 3 4 5 6 7 8 |
ActionController::Routing::Routes.draw do |map| map.resources :users do |user| user.resource :password end end |
Goes from
1 2 3 4 5 6 |
class UsersController < ApplicationController end class PasswordController < ApplicationController end |
to
1 2 3 4 5 6 |
class UsersController < ApplicationController end class PasswordsController < ApplicationController end |
What trash.
I’ve refused to accept this new singular resource plural controller name style and have resorted to specifying controller names in my routes.rb file.
1 2 3 4 5 6 7 8 |
ActionController::Routing::Routes.draw do |map| map.resources :users do |user| user.resource :password, :controller => 'password' end end |
Now I have to use this ugly hash of parameters to my #resource call (also Rails when are you going to let me use symbols for controller names? Strings are hideous and break up the flow of my code).
I might have to patch Rails or at least say I will and not do anything.
About this entry
You're reading an entry on GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS, the company weblog of thoughtbot, inc.
- Author:
- Jared Carroll
- Published:
- January 8th 04:22 PM
- Updated:
- January 8th 06:06 PM
- Sections:
- Technology
thoughtbot is hiring
We are hiring web developers and web designers in both Boston and New York, NY.
What are we up to?
We built Shoulda, an eclectic set of additions to Test::Unit; Paperclip to manage uploaded files without hassle; Jester, a REST/ActiveResource client library written in Javascript, and Squirrel, an enhancement for ActiveRecord's find syntax; — amongst some other projects.

Chad (President) and Jon (CTO) co-authored a technical book titled Pro Active Record: Databases with Ruby and Rails, which explores the ins and outs of the ActiveRecord ruby library. You can buy it today at Amazon.com.
About thoughtbot, inc.
We are a small web application development consulting business, with offices in Boston, MA and New York, NY. If you're looking to find a team for your next web development project or your new web application — get in touch.
11 comments
Jump to comment form