首页 > 解决方案 > 尝试设置路由路径,但没有路由匹配

问题描述

我在设置视图时遇到了大问题.. 每当我进入我的页面 localhost/clear 时,我都会得到 No route matches [GET] "/clear".

我的控制器中有一个名为 clear 的文件夹,其中包含控制器文件。

我如何将其设置为:

localhost/clear as main view, 
and other one as
localhost/clear/connect
localhost/clear/test

base_controller.rb

class Clear::BaseController < ApplicationController  
    def index  
    end  
    end  

连接控制器.rb

class Clear::ConnectController< Clear::BaseController

    def index 
       @functions
end
end

路线.rb

   resources :clear, only: :index
   namespace :clear do
    resources :connect, only: :index
    resources :test, only: :index
end

标签: ruby-on-railsrubyruby-on-rails-3

解决方案


你错过了路线/clear

# routes.rb

namespace :clear do
  resources :base, only: :index, path: '/'
  resources :connect, only: :index
  resources :test, only: :index
end

这是检查您拥有哪些路线的方法

rake routes | grep clear
# =>
clear_base_index GET    /clear(.:format)           clear/base#index
clear_connect_index GET /clear/connect(.:format)   clear/connect#index                                                                                   
clear_test_index GET    /clear/test(.:format)      clear/test#ind

推荐阅读