Lost in routing


#1

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/ everything is
fine, but once I access one of the shortcuts, i.e.
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. 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 - coming soon!


#2

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’


#3

Hi Jon,

Yeah, that did it :slight_smile:

Bye,

Guy.

On 1/31/06, Jon G. 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


Bye,

Guy

Family management on rails: http://www.famundo.com - coming soon!


#4

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

Bye,

Guy

Family management on rails: http://www.famundo.com - coming soon!