首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >正在尝试设置路由路径,但未获得匹配的路由

正在尝试设置路由路径,但未获得匹配的路由
EN

Stack Overflow用户
提问于 2021-03-20 21:27:23
回答 1查看 28关注 0票数 1

我在建立我的观点时遇到了很大的问题..每当我转到我的页面localhost/clear时,我都会得到No route matches [GET] "/clear".

我在控制器中有一个名为clear的文件夹,里面有控制器文件。

我如何将其设置为:

代码语言:javascript
复制
localhost/clear as main view, 
and other one as
localhost/clear/connect
localhost/clear/test

base_controller.rb

代码语言:javascript
复制
class Clear::BaseController < ApplicationController  
    def index  
    end  
    end  

connect_controller.rb

代码语言:javascript
复制
class Clear::ConnectController< Clear::BaseController

    def index 
       @functions
end
end

routes.rb

代码语言:javascript
复制
   resources :clear, only: :index
   namespace :clear do
    resources :connect, only: :index
    resources :test, only: :index
end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-20 22:00:21

您错过了到/clear的路由

代码语言:javascript
复制
# routes.rb

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

下面是如何检查您拥有哪些路径的方法

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66722138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档