Forum: Ruby on Rails How to route /app/name to /name?

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.
Wai T. (Guest)
on 2007-03-31 00:35
Hi,

From the rail recipe book, I found that it is possible to set up route
rule so that the url can parsed and map differently.  However, what I am
trying to accomplish is that if /abc is typed and the controller abc
does not exists, it will try to look into /app (i.e. app/abc).  Is this
possible?
wilson (Guest)
on 2007-03-31 00:40
(Received via mailing list)
map.connect ":name", :controller => "app"
where name is a GET parameter feed into the url on a link_to (or you
can type your domain_name/<whatever_name> to access the page
directly).

On Mar 30, 1:35 pm, Wai T. <removed_email_address@domain.invalid>
Wai T. (Guest)
on 2007-03-31 00:45
wilson wrote:
> map.connect ":name", :controller => "app"
> where name is a GET parameter feed into the url on a link_to (or you
> can type your domain_name/<whatever_name> to access the page
> directly).
>
> On Mar 30, 1:35 pm, Wai T. <removed_email_address@domain.invalid>

Thanks for the quick reply, but that route will only get to the app
controller with params[:name] = 'abc'.  I would like to go to the abc
method instead of the index method, is it possible?
Michael K. (Guest)
on 2007-03-31 01:53
(Received via mailing list)
Hi Wai,

I use this exact route in my app for user homepages:

   map.connect ':id', :controller => 'user', :action => 'user_home'

this will make http://foo.com/joe map to that controller and action
and pass the username joe to it
There might be a better way even as I believe I'm perverting the use
of :id in this case

-Michael
http://javathehutt.blogspot.com
wilson (Guest)
on 2007-03-31 03:45
(Received via mailing list)
Ff I'm reading it correctly, you want to get to the action 'abc' with
a controller of 'app'?

map.connect "abc", :controller => "app", :action => "abc"

This only requires the controller and the action when you create a
link_to.
As for the url, "domain_name/abc" should work.

On Mar 30, 1:45 pm, Wai T. <removed_email_address@domain.invalid>
Jeff C. (Guest)
on 2007-03-31 04:13
(Received via mailing list)
On Mar 30, 3:35 pm, Wai T. <removed_email_address@domain.invalid>
wrote:
> Hi,
>
> From the rail recipe book, I found that it is possible to set up route
> rule so that the url can parsed and map differently.  However, what I am
> trying to accomplish is that if /abc is typed and the controller abc
> does not exists, it will try to look into /app (i.e. app/abc).  Is this
> possible?

Actually it's pretty easy.  In your routes.rb, try this:

 map.connect '/:action', :controller => 'app'

However, the order of your route rules in routes.rb is very
important!  Higher routes take priority.  So if you still have the
default catch-all route that Rails generates for you in your routes.rb
(the :controller/:action:/:id route) make sure your route is *above*
it.

Also, you might not need that / that I've written.  It could be that
map.connect ':action', :controller => 'app' is correct.

Whenever I have problems with routes, I comment out all the other
routes, try the url in the browser again, and then look at the
development log for an error message - it will tell you what it
*thought* it was supposed to do with the url, which is usually enought
insight to solve the problem.

Jeff
softiesonrails.com
This topic is locked and can not be replied to.