After about a week playing with Rails, I have built a couple of apps but
am still unable to get one thing to work: subfolders. (I am probably
using the wrong term here, but oh well…)
I would like my rails application to have controllers logically grouped
into folders. So for instance:
http://domain.com/accounting/accounts
http://domain.com/hr/employees
Here’s how I have tried to accomplish this:
- Create folder ‘accounting’ in /app/controllers/
- In /app/controllers/accounting, create ‘accounts_controller.rb’
class AccountsController < ApplicationController
def index
end
end - Create folder ‘accounting’ in /app/views/
- Create folder ‘accounts’ in /app/views/accounting/
- In /app/views/accounting, create ‘index.rhtml’
Testing accounting accounts index
- Create folder ‘accounting’ in /app/helpers/
- In /app/helpers/accounting, create ‘accounts_helper.rb’
module AccountsHelper
end
Then if I fire up WEBrick and navigate to URL
http://localhost:3000/accounting/accounts, I ge the following error:
LoadError in #
Already loaded file
‘./script/…/config/…/app/controllers/accounting/accounts_controller.rb’
but ‘AccountingController’ was not set, perhaps you need to rename
‘./script/…/config/…/app/controllers/accounting/accounts_controller.rb’?
Any help would be appreciated. Right now I have resorted to having ALL
of my controllers in the same directory and using grotesquely long
names, i.e.
http://domain.com/accounting_accounts
which violates the principle of pretty urls.