# Another routes question

**URL:** <https://www.ruby-forum.com/t/another-routes-question/95677>\
**Category:** Rails\
**Created:** [June 8, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677 "2006-06-08T21:33:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 8, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677/1 "2006-06-08T21:33:17Z")

</div>

i need help setting up the routes for my app.

I have created about 10 controllers in the app/controllers/pro  
directory:  
app/controllers/pro/address\_controller.rb  
app/controllers/pro/certification\_controller.rb  
app/controllers/pro/program\_controller.rb  
app/controllers/pro/program\_controller.rb  
and so on…

The problem is that I would like to also use app/controllers/pro as a  
controller; so app/controllers/pro\_controller.rb

i know my routes are wrong but this is what i have:

map.connect ‘:controller/service.wsdl’, :action =\> ‘wsdl’  
map.connect “pro/:controller/:action”  
map.connect “pro/”,  
:controller=\>“pro”,  
:action=\>“index”

# Install the default route as the lowest priority.

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

Any help would be appreciated,

Nate

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 8, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677/2 "2006-06-08T21:48:06Z")

</div>

> The problem is that I would like to also use app/controllers/pro as a  
> controller; so app/controllers/pro\_controller.rb

If you want your app to work in the simple way that most people do, you  
shouldn’t have to mess with custom routes too much.

for instance, if you are developing on your localhost,  
‘localhost:3000/pro’ should render the ‘index’ action of your pro  
controller automatically.

Where you want to mess with your routes most of the time, is if you want  
to set up a default controller for something like localhost/, (the  
equivalent of [www.site.com](http://www.site.com))

There you can setup something like:  
map.connect ‘’, :controller =\> ‘pro’, :action =\> ‘index’

which sets the base controller for your app for someone who arrives at  
[yoursite.com](http://yoursite.com) instead of [yoursite.com/pro](http://yoursite.com/pro).

Does that clear anything up?

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 8, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677/3 "2006-06-08T22:44:54Z")

</div>

I think i understand how routes work and that explanation also helps but  
the problem i’m running into is this…

without specifying any routes (except for the default) when i try to go  
to  
localhost:3000/pro it works and takes me to the index action of the  
app/controllers/pro\_controller.rb; however, when i try to go to  
localhost:3000/pro/address I want to access the index action of  
app/controllers/pro/address\_controller.rb but instead it’s looking for  
the address action of app/controllers/pro\_controller.rb .

that’s essentially where my problem is; do i need to configure routes to  
get around this?

I know that i could create an individual route for every controller  
under app/controllers/pro like

map.connect ‘pro/address/:action’,  
:controller=\>“pro/address”

but that just does not make sense to me.

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 8, 2006, 11:06pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677/4 "2006-06-08T23:06:29Z")

</div>

You have conflicting controllers.

You can’t have a pro controller and a pro folder… you’ve got to pick  
one or the other.

Best thing do do is make a pro/base\_controller.rb and then route  
requests for pro/ to that one.

map.connect 'pro/:action/:id, :controller =\> “pro/base”

See if that works. (untested but modified from a project where I do  
this with ‘admin/’

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 8, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677/5 "2006-06-08T23:19:00Z")

</div>

Brian H. wrote:

> You have conflicting controllers.
> 
> You can’t have a pro controller and a pro folder… you’ve got to pick  
> one or the other.
> 
> Best thing do do is make a pro/base\_controller.rb and then route  
> requests for pro/ to that one.
> 
> map.connect 'pro/:action/:id, :controller =\> “pro/base”
> 
> See if that works. (untested but modified from a project where I do  
> this with ‘admin/’

Brian,

I see where you’re going with this but when i do that and then try to  
access pro/address or any other pro/controller it thinks that address is  
the action of base now… as opposed to it’s own controller

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 11, 2006, 3:51am UTC](https://www.ruby-forum.com/t/another-routes-question/95677/6 "2006-06-11T03:51:36Z")

</div>

Paste your routes file. It has to do with the order of the routes.

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 8, 2006, 10:13pm UTC](https://www.ruby-forum.com/t/another-routes-question/95677/7 "2006-06-08T22:13:20Z")

</div>

Here is an explanation of routes:  
[http://rails.outertrack.com/notes/list\_new](http://rails.outertrack.com/notes/list_new)

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 11, 2006, 4:28am UTC](https://www.ruby-forum.com/t/another-routes-question/95677/8 "2006-06-11T04:28:46Z")

</div>

Whoops… Didn’t read your mail well enought. Sorry. Silly me.

you can’t have both pro and also pro/something controllers. It has to  
be named as something else.

I’m guessing you are trying to make a page that is /pro and then if  
you click something there you go to pages like /pro/address/12

Create a controller pro/front with action :index.  
map.connect ‘pro’, :controller =\> “pro/front”, :acton =\> ‘index’

On 6/11/06, Jon Gretar B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > :action=>"index"
> > 
> > ```
> > 
> > –  
> > Jon Gretar B.  
> > [http://www.jongretar.net/](http://www.jongretar.net/)

–

---

<div class="post-metadata">

**Author:** ![natec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@natec](https://www.ruby-forum.com/u/natec)\
**Post date:** [June 11, 2006, 4:24am UTC](https://www.ruby-forum.com/t/another-routes-question/95677/9 "2006-06-11T04:24:49Z")

</div>

What you are doing wrong is that your controller is not named pro but  
pro/pro. You did create the by the command script/generate controller  
‘pro/pro’ right?

This should work:  
map.connect ‘pro’, :controller =\> “pro/pro”, :acton =\> ‘index’

An then remove the line  
map.connect “pro/:controller/:action”  
as the default route should be fine.

On 6/8/06, Nate C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem is that I would like to also use app/controllers/pro as a
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–
