My rails 3 app runs in the background of a Apache/mod_proxy server.
In the rails app exists a mandatory prefix :site_pin
In Apache the i have the following to abstract my prefix:
ServerName example.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:3000/site/example/
ProxyPassReverse / http://localhost:3000/site/example/
<Location />
Order allow,deny
Allow from all
</Location>
In my my routes.rb i have the following:
resources :products
#RESTful fix
match 'site/:site_pin/:controller/', :action => 'index', :via => [:get]
match 'site/:site_pin/:controller/new', :action => 'new', :via => [:get]
match 'site/:site_pin/:controller/', :action => 'create', :via => [:post]
match 'site/:site_pin/:controller/:id', :action => 'show', :via => [:get]
match 'site/:site_pin/:controller/:id/edit', :action => 'edit', :via => [:get]
match 'site/:site_pin/:controller/:id', :action => 'update', :via => [:put]
match 'site/:site_pin/:controller/:id', :action => 'destroy', :via => [:delete]
Everything works fine in this way, but anyone has a better solution for remove this fix and make the routes.rb more clean?
scopewould be very effective for this. Replace what you posted above in your routes.rb with:Now, run
rake:routesin and you should see the following output::site_pinwill be available asparams[:site_pin].Naturally, you’ll be able to add other resources and routes into the scope block; all of which will be prefixed with
site/:site_pin.