Forum: Ruby on Rails Need help with routes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aaron D. (Guest)
on 2009-06-05 13:02
I will try to word this as simple as possible...

I made a scaffold called 'cover' then migrated the table.

Of course the index, show, edit, and new .html.erb files work correctly
when they are called BUT, when I created a new .html.erb called 'home' I
routed it as so:

map.connect '/covers/', :controller=>'covers', :action=>'home'

and added

def home
end

I get the error "Couldn't find Cover with ID=home"

I want that page to show content of the scaffold but before I add more
to the controller I want to make the page route "url" work.

Is my route wrong? Do I need to add something to the controller?

I'm trying to keep the application in 1 folder and staying away from the
has_many code.
Rakoth (Guest)
on 2009-06-05 14:12
(Received via mailing list)
Hi, Aaron D.!

Looks like you use "http://localhost:3000/covers/home" query instead
of  "http://localhost:3000/covers" for access to home action in covers
controller.
But it really stange, how you add a specific route..

try to use

map.resources :covers, :collection => { :home => :get }
# then use home_covers_path
# it should generate '/covers/home'

or, if you want only rename index action

map.home 'covers', :controller => 'covers', :action => 'index'
# then use home_path
# it should generate '/covers'

you can find much more competent explanation in this screencast
http://railscasts.com/episodes/34-named-routes
Aaron D. (Guest)
on 2009-06-05 22:01
 Thanks for the information. I was going off of what the book "Head
First Rails" explains on routes.

 Just to be clear.. I'm assuming "script/generate home_covers_path" will
make my specific path correct? I don't have much time to try it now but
I will tonight. I'll also look at that railscast before posting anymore
questions about routes. Thanks a whole lot!
This topic is locked and can not be replied to.