gpt4 book ai didi

ruby-on-rails - `add_route' : Invalid route name, 已在使用中:'root' (ArgumentError)

转载 作者:数据小太阳 更新时间:2023-10-29 06:41:07 25 4
gpt4 key购买 nike

我使用的是 rails 4.1.1 和 ruby​​ 2.1.1,我在设计方面遇到了问题,即我的路线。我以前用过很多次

devise_for :users

get 'pages/index'

# Route to Devise Login Page
devise_scope :user do
root to: "devise/sessions#new"
end

# Directing the user after login
authenticated :user do
root :to => 'pages#index'
end

但是我得到了错误

`add_route': Invalid route name, already in use: 'root'  (ArgumentError)

当尝试启动服务器时..我可以看到 root 被使用了两次,但就像我说的我过去已经能够做到这一点..有没有办法解决这个问题

谢谢

最佳答案

在 stackoverflow 上找到这条有用的评论

For Rails 4.0 you have to make sure you have unique names for the path helpers, like root to: "dashboard#show", as: :authenticated_root. Otherwise the authenticated root and the normal root route end up having the same name for their path helpers, which Rails 4.0 no longer allows

所以我像这样将经过身份验证的根更改为助手

 # Directing the user after login
authenticated :user do
root :to => 'pages#index', as: :authenticated_root
end

关于ruby-on-rails - `add_route' : Invalid route name, 已在使用中:'root' (ArgumentError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24267292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com