-2

Have and old rails 3 app with a routes.rb like this

RailsAppli::Application.routes.draw do
  root :to => "landing#pos", :constraints => { :host => "pos.com.ar" }

  root :to => "landing#desa", :constraints => { :host => "desa.com.ar" }

  root :to => "landing#plan", :constraints => { :host => "dise.com.ar" }

thats work fine but i upgraded to rails 4 and

Invalid route name, already in use: 'root' (ArgumentError)

Whats the problem.

Thanks.

roalz
  • 2,699
  • 3
  • 25
  • 42

2 Answers2

0

Updating answer based on: Separate Domain for Namespaced Routes in Rails 4

Shortened:

1) define a custom constraint class in lib/domain_constraint.rb:

class DomainConstraint
  def initialize(domain)
    @domains = [domain].flatten
  end

  def matches?(request)
    @domains.include? request.domain
  end
end

2) use the class in your routes with the new block syntax

constraints DomainConstraint.new('mydomain.com') do
  root :to => 'mydomain#index'
end

root :to => 'main#index'

or the old-fashioned option syntax

root :to => 'mydomain#index', :constraints => DomainConstraint.new('mydomain.com')
Community
  • 1
  • 1
nateleavitt
  • 1,210
  • 10
  • 9
  • ok, thanks. but i need to rooting diferents domains to certain landing in my app. Like pos.com.ar to landing#pos. In rails 3 this routes.rb are good whats is the rails 4 way? thanks – derfarg Mar 16 '17 at 22:01
  • Thanks but i need domains, are diferents domains and one app serves diferent landing pages for these domains. – derfarg Mar 16 '17 at 22:07
  • okay see this: http://stackoverflow.com/questions/24122140/separate-domain-for-namespaced-routes-in-rails-4 – nateleavitt Mar 16 '17 at 22:21
-1

Done!.

Only one root.

then

RailsAppli::Application.routes.draw do
    get '/', :to => "landing#pos", :constraints => { :host => "pos.com.ar" }

    get '/', :to => "landing#desa", :constraints => { :host => "desa.com.ar" }

    get '/', :to => "landing#plan", :constraints => { :host => "dise.com.ar" }

Thanks