Topic: Route and controller in subdirectory

Hello,

I've put all my admin controller in the a subdirectory admin :

/controllers/admin/category_controller.rb
/controllers/admin/forum_controller.rb

and my controller definition are

class Admin::CategoryController < ApplicationController
class Admin::ForumController < ApplicationController

I've also an admin controller in the controllers directory in order to achieve authentification :

class AdminController < ApplicationController

It work nice but I've been obliged to add these lines to my routes.rb file :

  map.connect 'admin/category/:action/:id', :controller => 'admin/category'
  map.connect 'admin/forum/:action/:id', :controller => 'admin/forum'

and if I use

<%= link_to "My account", :controller => "account", :action => "edit" %>

my link didn't work when I'am in the admin part (link displayed is /admin/account/edit and it should be /account/edit).

So what is wrong ? My routes.rb file ? My usage of link_to ?

Thanks a lot for your help !

Osaris

Re: Route and controller in subdirectory

I have a similar app structure, and this is what I did:

map.role 'admin/roles/:action/:id', :controller => 'admin/roles'

I'm using named routes instead of anonymous routes so that I can just call:

map_url

Re: Route and controller in subdirectory

osaris wrote:

<%= link_to "My account", :controller => "account", :action => "edit" %>

my link didn't work when I'am in the admin part (link displayed is /admin/account/edit and it should be /account/edit).

IIRC, this should work:

<%= link_to "My account", :controller => "/account", :action => "edit" %>

Railscasts - Free Ruby on Rails Screencasts

Re: Route and controller in subdirectory

ryanb wrote:
osaris wrote:

<%= link_to "My account", :controller => "account", :action => "edit" %>

my link didn't work when I'am in the admin part (link displayed is /admin/account/edit and it should be /account/edit).

IIRC, this should work:

<%= link_to "My account", :controller => "/account", :action => "edit" %>

It works ! Thanks !