0

I have a live Rails app. Now I would like to reroute all of them to a subdomain dev.mydomain.com.

For example, current path mydomain.com/users/1 should become dev.mydomain.com/users/1. All the links in my pages should work also.

How should I do this?

Thanks a lot.

Edit: the reason I want to do this is because I want to hide my app from visitors, and redirect them to a different landing page.

AdamNYC
  • 19,887
  • 29
  • 98
  • 154
  • You are messing up the terms path and url. What you want try to archive ? http://apidock.com/rails/ActionView/Helpers/UrlHelper/url_for , check out the :host parameter – astropanic May 15 '12 at 14:32
  • Hi, the reason I want to do this is because I want to hide my app from visitors, and redirect them to a different landing page. – AdamNYC May 15 '12 at 14:37
  • Are `dev.myomain.com` and `mydomain.com` separate rails apps? What's your deployment stack? (Apache, nginx, thin, webrick?). – Matt May 15 '12 at 14:41
  • No. They are in the same app. The app is in stealth mode and I want to have only my landing page exposed to visitors. `dev.mydomain.com` is to show the app to friends and invited visitors. – AdamNYC May 15 '12 at 14:56

1 Answers1

0

You could do the following

  1. Create a file in your config/lib directory called subdomain.rb then add this to it

    class Subdomain
        def self.matches?(request)
            if request.subdomain == "www" || request.subdomain.blank? || request.subdomain.empty? || request.subdomain.nil?
                false
            else
                true
            end
        end
    end
    

Then in your routes.rb you can do this

    require 'subdomain'

    DemoApp::Application.routes.draw do

        constraints(Subdomain)  do
            constraints(:subdomain => 'dev') do
                resources :users
                root :to => "someother#page"
            end
        end

        root :to => "default#index"

        # and any other routes you would like to expose to www or no subdomain.
    end

To run my apps I tend to use pow.cx and I would recommend the same.

David Geere
  • 404
  • 5
  • 10