nginx - Rails Domain Constraints ( to serve multiple domains ) -
$ rails -v rails 4.2.1
$ ruby -v ruby 2.2.2p95 (2015-04-13 revision > 50295) [x86_64-linux]
i building api mobile app, have admin interface it. i'm attempting do, run through nginx using unicorn ( have running on dev environment)
i have 2 domains routed exact same rails project. these domains are: api.project.dev , admin.api.project.dev
i've read this: http://guides.rubyonrails.org/routing.html#advanced-constraints
and tried: separate domain namespaced routes in rails 4 ( see answer )
i've tried few other things try , work, thing comes ( either sub-domain ) is:
invalid route name, in use: 'root'
my current implementation of is:
class domainconstraint def initialize(domain) @domains = domain end def matches?(request) @domains.include? request.domain end end and
require 'domain_constraint' rails.application.routes.draw resources :statuses constraints (domainconstraint.new('api.project.dev')) root :to => 'statuses#index' end constraints(domainconstraint.new('admin.api.project.dev')) root :to => 'statuses#new' end end keep in mind roots different pages now, different systems.
not quite sure go here in order functioning hope.
with fine of great people in #rubyonrails on irc got figured out. crankharder , sevenseacat input , advice.
what ended this:
class domainconstraint def initialize(domain) @domains = domain end def matches?(request) @domains.include? request.host end end and:
require 'domain_constraint' rails.application.routes.draw constraints domainconstraint.new('api.project.dev') resources :statuses root :to => 'statuses#index', as: 'api_root' end constraints domainconstraint.new('admin.api.project.dev') resources :statuses root :to => 'statuses#new' end end
Comments
Post a Comment