URL prefix in a Rails application

I want all my pages in a 2.3 Rails app to have a URL with a prefix:

www.example.com/app/

and I wrote in the routes.rbfollowing 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'

Everything works fine except map.resourceswhere I have

map.resources :pages

and now wherever I have edit_page_pathor page, the generated url is incorrect, because it is appnot inserted at the beginning. I tried with namespaceand scope, as I saw here in chapter 2.6 , but without success.

How should I do it? Is :applroutes a bad idea?

+5
source share
2 answers

Here is how I wrote in routes.rb:

map.resources :pages,   :as => 'app/pages'

edit_page_path 'app'

0

Passenger, ( -):

RailsBaseURI /app

config:

config.action_controller.relative_url_root = '/app'

- -uri . . . .

mongrel --prefix

script/server mongrel -P /app
+6

All Articles