I have created about 10 controllers in the app/controllers/pro
directory:
app/controllers/pro/address_controller.rb
app/controllers/pro/certification_controller.rb
app/controllers/pro/program_controller.rb
app/controllers/pro/program_controller.rb
and so on…
The problem is that I would like to also use app/controllers/pro as a
controller; so app/controllers/pro_controller.rb
i know my routes are wrong but this is what i have:
The problem is that I would like to also use app/controllers/pro as a
controller; so app/controllers/pro_controller.rb
If you want your app to work in the simple way that most people do, you
shouldn’t have to mess with custom routes too much.
for instance, if you are developing on your localhost,
‘localhost:3000/pro’ should render the ‘index’ action of your pro
controller automatically.
Where you want to mess with your routes most of the time, is if you want
to set up a default controller for something like localhost/, (the
equivalent of www.site.com)
There you can setup something like:
map.connect ‘’, :controller => ‘pro’, :action => ‘index’
which sets the base controller for your app for someone who arrives at yoursite.com instead of yoursite.com/pro.
I think i understand how routes work and that explanation also helps but
the problem i’m running into is this…
without specifying any routes (except for the default) when i try to go
to
localhost:3000/pro it works and takes me to the index action of the
app/controllers/pro_controller.rb; however, when i try to go to
localhost:3000/pro/address I want to access the index action of
app/controllers/pro/address_controller.rb but instead it’s looking for
the address action of app/controllers/pro_controller.rb .
that’s essentially where my problem is; do i need to configure routes to
get around this?
I know that i could create an individual route for every controller
under app/controllers/pro like
See if that works. (untested but modified from a project where I do
this with ‘admin/’
Brian,
I see where you’re going with this but when i do that and then try to
access pro/address or any other pro/controller it thinks that address is
the action of base now… as opposed to it’s own controller
What you are doing wrong is that your controller is not named pro but
pro/pro. You did create the by the command script/generate controller
‘pro/pro’ right?
This should work:
map.connect ‘pro’, :controller => “pro/pro”, :acton => ‘index’
An then remove the line
map.connect “pro/:controller/:action”
as the default route should be fine.