Hello everybody. I’m in the process of developing a site on Rails
2.0.2, and having migrated from the early 1.x days, I’m still getting
my feet wet with the new REST-based controllers. For the most part,
the REST controllers generated by scaffold have been painless to use
so far. I ran into a problem last night when I tried to add a method
to a controller outside of the REST domain. A dumbed down example
class CoursesController < ApplicationController
render :text => “Hello”
Trying to access http://mysite.com/courses/hello would yield.
Couldn’t find Course with ID=hello
I understand why this is happening. The controller is trying to use
hello as a course ID because of the REST URI layout, but what do I do
if I want to define a custom method on my controller? My solution last
night was to modify routes.rb and add something like the following
above the map.resources :courses declaration:
map.connect ‘courses/hello’, :controller => ‘courses’, :action =>
This seems to work, but I’m wondering if it’s the right way to do it.
Maybe I’m never supposed to diverge from the REST domain, but there
are times when it’s sort of a necessity. Can anybody tell me if I’m on
the right track, or is there a better way?