bdx
bdx

Reputation: 3516

Rails 3 Routes - prepend all url paths with set string

I've been asked to change the routes on a Rails project such that the routes will only respond to requests where the app name (or other arbitrary string) is the first string after the domain name, e.g.

www.thething.com/appname/users/sign_in instead of www.thething.com/users/sign_in

www.thething.com/appname instead of www.thething.com

www.thething.com/appname/search instead of www.thething.com/search

I've suggested using a subdomain appname.thething.com instead, but the client is quite specific about wanting the URL in the above format.

www.thething.com will be a splash page which will contain a link to www.thething.com/appname, with the intention of adding additional apps/pages in future with new folder names.

Is there an easy way of modifying the routes file so that all routes will get the .../appname prepended to all resources and routes, while being after the domain?

Upvotes: 0

Views: 959

Answers (1)

drewinglis
drewinglis

Reputation: 434

One option is wrap all existing routes in: namespace :appname do ... end, like so:

# config/routes.rb
Appname::Application.routes.draw do
  namespace :appname do
    # existing routes go here
  end
end

I'm not sure if this is the most elegant solution, but it will prepend /appname to all the routes.

Upvotes: 1

Related Questions