# Lost in routing

**URL:** <https://www.ruby-forum.com/t/lost-in-routing/99590>\
**Category:** Rails\
**Created:** [January 31, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/lost-in-routing/99590 "2006-01-31T23:00:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [January 31, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/lost-in-routing/99590/1 "2006-01-31T23:00:15Z")

</div>

I’m trying to create a modules based system where my controllers are  
all under modules. So the structure looks something like:

app/  
controllers/  
message/  
news\_controller.rb  
email\_controller.rb  
library  
books\_controller.rb  
pictures\_controller.rb  
home\_page\_controller.rb

Each of those controller has it’s own view, and there’s a central  
application.rhtml for the layout. The layout has in it links to each  
of the controllers using the form:  
url\_for(:controller =\> ‘message/news’, :action =\> ‘show’)

The routing is:  
map.connect ‘’, :controller =\> ‘home\_page’, :action =\> ‘show’  
map.connect ‘/home\_page’, :controller =\> ‘home\_page’, :action =\>  
‘show’  
map.connect ‘/news’ , :controller =\> ‘message/news’ , :action =\>  
‘show’  
map.connect ‘/books’ , :controller =\> ‘library/books’ , :action =\>  
‘show’

# Install the default route as the lowest priority.

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

When I access the initial page - [http://localhost:3000/](http://localhost:3000/) everything is  
fine, but once I access one of the shortcuts, i.e.  
[https://localhost:3000/books](https://localhost:3000/books), the url\_for(:controller =\>  
‘message/news’, :action =\> ‘show’) will return a wrong url. What I get  
is:  
[http://localhost:3000/books/message/news/show](http://localhost:3000/books/message/news/show). As you can see the  
/books part remains part of the URL, though I don’t see why the  
url\_for() will not ignore this part. Actually, url\_for returns  
/books/message/news/show. The protocol and host are added by the  
client. But still, the /books part should not be there.

Any pointers as to how I should handle that?

Bye,

Guy

Family management on rails: [http://www.famundo.com](http://www.famundo.com) - coming soon!

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [January 31, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/lost-in-routing/99590/2 "2006-01-31T23:18:21Z")

</div>

I think you just need to add a beginning slash to your :controller  
declarations:

> map.connect ‘/news’ , :controller =\> ‘/message/news’ , :action  
> =\> ‘show’  
> map.connect ‘/books’ , :controller =\> ‘/library/books’ , :action  
> =\> ‘show’

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 1, 2006, 1:03am UTC](https://www.ruby-forum.com/t/lost-in-routing/99590/3 "2006-02-01T01:03:57Z")

</div>

Hi Jon,

Yeah, that did it 🙂

Bye,

Guy.

On 1/31/06, Jon G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I’m trying to create a modules based system where my controllers are  
> > home\_page\_controller.rb  
> > map.connect ‘/news’ , :controller =\> ‘message/news’ , :action =\>  
> > is:  
> > Guy  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Bye,

Guy

Family management on rails: [http://www.famundo.com](http://www.famundo.com) - coming soon!

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 1, 2006, 4:49am UTC](https://www.ruby-forum.com/t/lost-in-routing/99590/4 "2006-02-01T04:49:57Z")

</div>

Maybe I can save some time for other people…

Here’s a small blog entry on this routes with modules thing:  
[http://devblog.famundo.com/articles/2006/01/31/modules-and-routes](http://devblog.famundo.com/articles/2006/01/31/modules-and-routes)

Bye,

Guy

Family management on rails: [http://www.famundo.com](http://www.famundo.com) - coming soon!
