Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prefix urls in Rails application

I want all my pages in my 2.3 Rails application to have the url prefixed with:

www.example.com/app/

and I did this writing in routes.rb the following lines:

# I named the first part of the url ':appl'
map.root :appl => "app", :controller => "home"

# Default routes
map.connect ':appl/:controller/:action/:id'
map.connect ':appl/:controller/:action/:id.:format'

It all works fine, with the exception of map.resources, where I have

map.resources :pages

and now wherever I have edit_page_path or page, the generated url's are not correct, because app is not inserted at the beginning. I've tried with namespace and scope, like I've seen here in chapter 2.6, but with no success.

How should I do this? Is the :appl in routes a bad idea?

like image 272
True Soft Avatar asked Jan 16 '11 20:01

True Soft


1 Answers

If you are deploying on Passenger, you just need to set (in your webserver config):

RailsBaseURI /app

And then in your app's config:

config.action_controller.relative_url_root = '/app'

You shouldn't need to worry about any sub-uri stuff beyond that. It should Just Work. See the Passenger documentation for more details.

For mongrel, you can use the --prefix option

script/server mongrel -P /app
like image 85
Chris Heald Avatar answered Oct 21 '22 15:10

Chris Heald