Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4静态子域_Ruby On Rails_Ruby On Rails 4_Routes_Subdomain - Fatal编程技术网

Ruby on rails Rails 4静态子域

Ruby on rails Rails 4静态子域,ruby-on-rails,ruby-on-rails-4,routes,subdomain,Ruby On Rails,Ruby On Rails 4,Routes,Subdomain,我无法为子域设置根路径 这是我的routes.rb部分: 当我访问blog.example.com时,我得到了staticindex操作响应,当我访问blog.example.com/posts时,我得到了postsindex 我想为blog.example.com设置指向postsindex的根路径 对此没有影响: match '/' => 'posts#index', :constraints => { :subdomain => 'blog' }, via: [:get]

我无法为子域设置根路径

这是我的routes.rb部分:

当我访问blog.example.com时,我得到了staticindex操作响应,当我访问blog.example.com/posts时,我得到了postsindex

我想为blog.example.com设置指向postsindex的根路径

对此没有影响:

match '/' => 'posts#index', :constraints => { :subdomain => 'blog' }, via: [:get]

我相信您仍然可以在约束块中调用root:


对于我来说,每个子域都有单独的名称空间

您是否关心routes.rb文件中的顺序?Rails将采用第一条匹配路线。因此,请始终在受约束的路由之后放置更多常规路由是的,例如,“main”root是routes.rbIt中的最后一条记录。rbIt根本不起作用:当我运行rails服务器时,我遇到了一个错误:未捕获的异常:无效的路由名称,已在使用中:“root”您可能使用:as选项定义了两条同名路由,或者,您可能正在覆盖已由具有相同名称的资源定义的路由。对于后者,您可以限制使用资源创建的路由,如下所述:http://guides.rubyonrails.org/routing.htmlrestricting-the-routes-created 当我使用root:to=>'postsindex',:as=>blog时,我可以启动rails服务器,但是blog.example.com指向staticsindex
match '/' => 'posts#index', :constraints => { :subdomain => 'blog' }, via: [:get]
constraints subdomain: 'blog' do
  root :to => 'posts#index' # Perhaps this needs to be `blog/posts#index`?

  scope :module => "blog", :as => "blog" do
    resources :posts
  end
end

root 'statics#index'