Forum: Ruby on Rails Routes question

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.
503bc7d692463e15d9a66fb50c5173a3?d=identicon&s=25 Timothy Johnson (Guest)
on 2006-01-23 06:29
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:

www.domiain.com/5405551212

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
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-01-23 06:47
(Received via mailing list)
map.connect ':phone', :controller => 'yourcontroller'

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

I think. :-)

--
-- Tom Mornini
2de6da7e2acab1aa80c3cc8942f444e2?d=identicon&s=25 Timothy Johnson (jhnsntmthy)
on 2006-01-23 06:50
Tom Mornini 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.
855c677aca7319a44da19fb583b9f320?d=identicon&s=25 Nicolas Cavigneaux (Guest)
on 2007-09-25 22:43
(Received via mailing list)
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 Cavigneaux
http://www.bounga.org
http://www.cavigneaux.net
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-09-25 22:47
(Received via mailing list)
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"
855c677aca7319a44da19fb583b9f320?d=identicon&s=25 Nicolas Cavigneaux (Guest)
on 2007-09-25 22:48
(Received via mailing list)
Le 8 janv. 07 à 14:19, Chris Hall 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 :-)
--
Nicolas Cavigneaux
http://www.bounga.org
http://www.cavigneaux.net
855c677aca7319a44da19fb583b9f320?d=identicon&s=25 Nicolas Cavigneaux (Guest)
on 2007-09-25 22:49
(Received via mailing list)
Le 6 janv. 07 à 19:15, Chris Hall 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 Cavigneaux
http://www.bounga.org
http://www.cavigneaux.net
855c677aca7319a44da19fb583b9f320?d=identicon&s=25 Nicolas Cavigneaux (Guest)
on 2007-09-25 22:51
(Received via mailing list)
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 Cavigneaux
http://www.bounga.org
http://www.cavigneaux.net
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2007-09-25 22:52
(Received via mailing list)
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.
This topic is locked and can not be replied to.