Routes question

Newbie here, I am trying to set up Routes so that it will look up a
listing in my directory by sanitized phone number, like the following:

which will in turn list all the listings with that phone number (though
they might be in the Db table with parenthesis and hyphens), if one
listing, then make it a special render

If anyone could help with my Routes code and my controller, I would
appreciate it

Tim

map.connect ‘:phone’, :controller => ‘yourcontroller’

This will invoke yourcontroller at method index, and
the phone number would be in params[:phone]

I think. :slight_smile:


– Tom M.

Tom M. wrote:

map.connect ‘:phone’, :controller => ‘yourcontroller’

This will invoke yourcontroller at method index, and
the phone number would be in params[:phone]

Yes, this does work well enough thank you.

So my routes.rb is like that :

ActionController::Routing::Routes.draw do |map|
map.home ‘’, :controller => “home”

Admin routes

map.connect ‘admin/category’, :controller => ‘admin/category’
map.connect ‘admin/content’, :controller => ‘admin/content’
map.connect ‘admin/definition’, :controller => ‘admin/definition’
map.connect ‘admin/file’, :controller => ‘admin/file’
map.connect ‘admin/layout’, :controller => ‘admin/layout’

Content route

map.content ‘:category/:content’, :controller => “home”, :action
=> “show”

Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id’
end

It’s so ugly …

Any idea ?

Nicolas C.

Le 8 janv. 07 à 14:19, Chris H. a écrit :

unfortunately when using controllers that way, I don’t think there is
any way to setup routes any differently. perhaps someone else on the
list has some additional insight.

Ok, thank you for help :slight_smile:

Nicolas C.

unfortunately when using controllers that way, I don’t think there is
any way to setup routes any differently. perhaps someone else on the
list has some additional insight.

one potential problem would be if someone tried to access an admin
route that did not exist, such as /admin/whatever’. it would not
match any of your defined admin routes and would then pass to
‘:category/:content’ which would be routed to ‘home/show’…something
to watch for. i think one additional route to catch anything else.

‘admin/:missing’ might be needed and could be routed to a 404 page or
something.

keep in mind that you’re not going to be editing routes much. so while
you might consider it ugly, it’s only in the routes.rb file and not
the rest of your code.

you might want to go one extra step and use named routes as that will
make the rest of your code a bit prettier.

ie

map.category_admin ‘admin/category’, :controller => ‘admin/category’

then any link to that will be

link_to “Category Admin”, category_admin_url, …

rather than

link_to “Category Admin”, :controller => “admin/category”

Le 8 janv. 07 à 14:29, Jean-François a écrit :

Have you tried :

map.connect ‘admin/:controller/:action/:id’

Yes but it doesn’t work.

Nicolas C.

Nicolas :

map.connect ‘admin/layout’, :controller => ‘admin/layout’

Content route

map.content ‘:category/:content’, :controller => “home”, :action
=> “show”

Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id’
end

It’s so ugly …

Have you tried :

map.connect ‘admin/:controller/:action/:id’

– Jean-François.


À la renverse.

Le 6 janv. 07 à 19:15, Chris H. a écrit :

you shouldn’t have to create a route for each module in your admin
area

map.admin ‘admin/:action’, :controller => ‘admin’

should be enough.

It can’t work because ‘admin/content’ or ‘admin/category’ are
controllers because I’m using this :

class Admin::ContentController < Admin::BaseController

The only way I can find is to write a route for each module, eg:

map.admin_content ‘admin/content’, : controller => ‘admin/content’

It’s a bit strange to do that …

Nicolas C.