Forum: Ruby on Rails Lost in routing

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.
Just S. (Guest)
on 2006-02-01 00:00
(Received via mailing list)
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!
Jon G. (Guest)
on 2006-02-01 00:18
(Received via mailing list)
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'
Just S. (Guest)
on 2006-02-01 02:03
(Received via mailing list)
Hi Jon,

Yeah, that did it :-)

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!
Just S. (Guest)
on 2006-02-01 05:49
(Received via mailing list)
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/mod...

Bye,

Guy

Family management on rails: http://www.famundo.com - coming soon!
This topic is locked and can not be replied to.