Forum: Ruby on Rails routing a restful controller to work from site root

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.
7b2880cb9d7d75511c9b4448c016f62d?d=identicon&s=25 Marc na (marconrails)
on 2007-07-06 22:08
(Received via mailing list)
hi i have rewritten my map.resources so that a resource is called from
the start: map.connect '', :controller => "resource"

so www.mysite.com lists the available resource

however i want www.mysite.com/1 to show one of a particular resource
rather than www.mysite.com/show/1 as is the default restful route.

how can i get this url?

thanks
Cabf735ce7b8b4471ef46ea54f71832d?d=identicon&s=25 Michael Mahemoff (Guest)
on 2007-07-06 22:19
Marc Rice wrote:
> hi i have rewritten my map.resources so that a resource is called from
> the start: map.connect '', :controller => "resource"
>
> so www.mysite.com lists the available resource
>
> however i want www.mysite.com/1 to show one of a particular resource
> rather than www.mysite.com/show/1 as is the default restful route.
>
> how can i get this url?
>

map.connect ':id', :controller => "resources", :action=>"show"
7b2880cb9d7d75511c9b4448c016f62d?d=identicon&s=25 Marc na (marconrails)
on 2007-07-06 22:41
(Received via mailing list)
this is great but what about with nested resources?

thanks

On Jul 6, 9:19 pm, Michael Mahemoff <rails-mailing-l...@andreas-s.net>
21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-07-07 09:13
(Received via mailing list)
A few things in you post don't make sense to me...

1. You say that www.mysite.com/show/1 is a "RESTful route," but it's
not.  RESTful routes don't include the action (show) in this case.
Say if your resource/model was Post then the RESTful URL would look
something like www.mysite.com/posts/1.  Notice there's no mention of
the action.  The action is based on the HTTP verb used to access the
URL.  Show would be a GET request, POST to create, PUT to update,
DELETE to destroy.

2. If you are using RESTful routes you would use map.resources not
map.connect to declare your resources, which in turn creates the
RESTful URLs.

3. If what you really mean is that you want to drop the resource out
of the URL, which I must assume your application has only one main
resource and everything else in the database is nested, then you would
need to use map.connect or a named route to do that.
This topic is locked and can not be replied to.