【问题标题】:No route matches [GET] "/" when trying to add the gem devise尝试添加 gem 设计时没有路线匹配 [GET] "/"
【发布时间】:2021-09-28 14:14:13
【问题描述】:

错误自带

请在 config/routes.rb 中添加一些路由。

routes.rb 已经有

devise_for :users

我不确定如何修复此错误。我在 GIT 终端中尝试了rake routes,结果如下:

rake aborted!
Don't know how to build task 'routes' (See the list of available tasks with `rake --tasks`)

在本地服务器上以开发模式运行。

【问题讨论】:

    标签: ruby routes devise


    【解决方案1】:

    这么几样东西:

    首先,rake routes 已被删除 - 我不知道为什么 tbh,但现在改为 rails routes

    其次,devise 正在添加其路由,但您仍然需要设计一些其他内容来保护访问。你可以创建一个简单的HomeController

    class HomeController < ApplicationController
      def show
        render html: "home"
      end
    end
    

    并将其用作您的根路由:

    # routes.rb
    devise_for ...
    root to: "home#show"
    

    【讨论】:

    • 感谢您的帮助。实际上是通过重新启动我的计算机来解决的!
    猜你喜欢
    • 1970-01-01
    • 2014-07-05
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多