ruby-on-rails – `add_route’:路由名称无效,已经在使用:’root'(ArgumentError)

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – `add_route’:路由名称无效,已经在使用:’root'(ArgumentError)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用导轨4.1.1和ruby2.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)

当尝试启动服务器..我可以看到,根被使用了两次,但像我说我已经能够做到这一点在过去..有没有办法

谢谢

解决方法

在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相关文章