I configured Ruby on Rails to run with Apache, because I’m not too worried about speed and didn’t want to mess with proxies. I also configured the app to run in a subdirectory, using Apache’s Alias
directive to point to the app’s public directory. I’ll point out this is the first time I’ve ever looked at Ruby in my life, and my first time working with any MVC framework, although I’ve looked into them a bit.
I was getting the dreaded No route matches "/subdirectory/" with {:method=>:get}
error and it seemed pretty clear what the problem was. The app didn’t know it was in a subdirectory; I’d probably need to edit the routes to tell it so. It seems this is the last thing the people in Google-land were needing to do, but I eventually figured it out. I’d need to do something like this with the routes:
map.connect 'subdirectory/:controller/:action/:id'
So I took a look at routes.rb
and it was using resources, not traditional routes. So what do I do with that?
It took hours of searching before I found the answer to my problem — a testament to the quality of Rails’ documentation I suppose. The answer is path_prefix
map.resources :groups, :path_prefix => 'subdirectory/'
You can also use it for the root as well.
map.root :controller => 'start', :path_prefix => 'subdirectory/'
Now I just have to fix the fact that the author of the app hard coded all sorts of stuff with the assumption that the app wouldn’t be in a directory. Grrr.
Update: Turns out it’s even easier than that. I didn’t have to change routes.rb
at all.
config.action_controller.relative_url_root = '/subdirectory'
This has the added advantage of fixing things like linked stylesheets and stuff as well.