How to route /app/name to /name?


#1

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?


#2

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


#3

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?


#4

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


#5

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


#6

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