在ruby-on-rails的routes.rb文件中遇到了未知的错误,该如何解决?

更新于
2026-10-09 21:23:27
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计318个文字,预计阅读时间需要2分钟。

在ruby-on-rails的routes.rb文件中遇到了未知的错误,该如何解决?

嗨,我是Rails的新手。当我访问localhost时,我直接收到这个错误:3000+ 路由错误:没有线路匹配 [GET] /。我尝试运行rake routes以获取更多可用线路的信息。这就是我的routes.rb文件的样子。Sample

嘿,我是Rails的新手,当我去localhost时,我一直收到这个错误:3000 /

路由错误

没有路线匹配[GET]“/”
尝试运行rake路线以获取有关可用路线的更多信息.

这就是我的routes.rb文件的样子.

SampleApp::Application.routes.draw do get "static_pages/about" get "static_pages/contact" get "static_pages/help" get "static_pages/home" end

我的views文件夹看起来像这样

views/static_pages/about.html.erb views/static_pages/contact.html.erb views/static_pages/help.html.erb views/static_pages/home.html.erb

我运行了rake routes命令并得到以下信息:

Davids-MacBook-Air:sample_app DavidStevenson$rake routes static_pages_home GET /static_pages/home(.:format) static_pages#home static_pages_help GET /static_pages/help(.:format) static_pages#help static_pages_about GET /static_pages/about(.:format) static_pages#about static_pages_contact GET /static_pages/contact(.:format) static_pages#contact

任何想法都出错了?

在ruby-on-rails的routes.rb文件中遇到了未知的错误,该如何解决?

您只是忘了定义根路由.把它放在你的路线文件的末尾:

root to: 'static_pages#home'

现在,当您访问localhost:3000 /时,您将看到static_pages_home页面.

检查this guide以获取有关路线的所有信息.

编辑

以下是您的路径文件的外观:

SampleApp::Application.routes.draw do get "static_pages/about" get "static_pages/contact" get "static_pages/help" get "static_pages/home" root to: 'static_pages#home' end

标签:未知

本文共计318个文字,预计阅读时间需要2分钟。

在ruby-on-rails的routes.rb文件中遇到了未知的错误,该如何解决?

嗨,我是Rails的新手。当我访问localhost时,我直接收到这个错误:3000+ 路由错误:没有线路匹配 [GET] /。我尝试运行rake routes以获取更多可用线路的信息。这就是我的routes.rb文件的样子。Sample

嘿,我是Rails的新手,当我去localhost时,我一直收到这个错误:3000 /

路由错误

没有路线匹配[GET]“/”
尝试运行rake路线以获取有关可用路线的更多信息.

这就是我的routes.rb文件的样子.

SampleApp::Application.routes.draw do get "static_pages/about" get "static_pages/contact" get "static_pages/help" get "static_pages/home" end

我的views文件夹看起来像这样

views/static_pages/about.html.erb views/static_pages/contact.html.erb views/static_pages/help.html.erb views/static_pages/home.html.erb

我运行了rake routes命令并得到以下信息:

Davids-MacBook-Air:sample_app DavidStevenson$rake routes static_pages_home GET /static_pages/home(.:format) static_pages#home static_pages_help GET /static_pages/help(.:format) static_pages#help static_pages_about GET /static_pages/about(.:format) static_pages#about static_pages_contact GET /static_pages/contact(.:format) static_pages#contact

任何想法都出错了?

在ruby-on-rails的routes.rb文件中遇到了未知的错误,该如何解决?

您只是忘了定义根路由.把它放在你的路线文件的末尾:

root to: 'static_pages#home'

现在,当您访问localhost:3000 /时,您将看到static_pages_home页面.

检查this guide以获取有关路线的所有信息.

编辑

以下是您的路径文件的外观:

SampleApp::Application.routes.draw do get "static_pages/about" get "static_pages/contact" get "static_pages/help" get "static_pages/home" root to: 'static_pages#home' end

标签:未知