Rails Resources: :as vs :controller
Posted on November 15, 2008, under Coding.
As you may or may not know, when configuring routes and resources in config/routes.rb , you can pass the :as or :controller options to map.resources . When I first read about these two options in the Rails Routing From The Outside In Rails Guide, they seemed to do the exact same thing.
However, that’s not the case at all.
map.resources :photos, :as => 'images'
This allows you to request the “photos” resource using the word “images”. IE: http://localhost:3000/images/ would route to the “photos” controller.
On the other hand,
map.resources :photos, :controller => 'images'
This allows you to request the “images” resource using the word “photos”. IE: http://localhost:3000/photos/ would route to the “images” controller.
Simple? Yes. Subtle? Yes.
ModelSpeccer Released!
Yesterday I released my first open-source project. It’s called ModelSpeccer, and it generates RSpec specs on-the-fly for Rails model attributes. It started out as part of my housing rentals website, and eventually grew into a separate module. Once that happened, I figured I might as well learn how to write a Rails plugin, and published it on GitHub. Have a look:
http://github.com/nickhoffman/modelspeccer/