加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – `add_route’:路由名称无效,已经在使用:’ro

发布时间:2020-12-16 21:33:33 所属栏目:百科 来源:网络整理
导读:我使用导轨4.1.1和ruby2.1.1,我有一个设计问题,即我的路线.我已经使用了这么多次 devise_for :usersget 'pages/index'# Route to Devise Login Page devise_scope :user do root to: "devise/sessions#new" end# Directing the user after login authenticat
我使用导轨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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读