Ruby on rails `添加路径';:无效的路由名称,已在使用中:';新用户会话';(错误)
我无法通过Heroku让我的应用程序在生产中运行。这是一个在开发中完全可以工作的应用程序 我对这个问题进行了研究,但许多解决方案都是因为它们的Ruby on rails `添加路径';:无效的路由名称,已在使用中:';新用户会话';(错误),ruby-on-rails,ruby,heroku,routes,precompile,Ruby On Rails,Ruby,Heroku,Routes,Precompile,我无法通过Heroku让我的应用程序在生产中运行。这是一个在开发中完全可以工作的应用程序 我对这个问题进行了研究,但许多解决方案都是因为它们的路径中有一个重复的设计。我的应用程序没有这个问题,而且我很难找到重复发生的地方 这是完整的错误消息: /app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:557:in `add_route': Invalid route n
路径中有一个重复的设计。我的应用程序没有这个问题,而且我很难找到重复发生的地方
这是完整的错误消息:
/app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:557:in `add_route': Invalid route name, already in use: 'new_user_session' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
这是我当前的routes.rb
文件:
Rails.application.routes.draw do
devise_for :users, :controllers => { registrations: 'registrations' }
get 'items/create'
get 'welcome/index'
get 'about' => 'welcome#about'
get 'brandon' => 'welcome#brandon'
root 'welcome#index'
resources :users, only: [:index, :show] do
resources :items
end
end
我已经更新了我的gems,删除了数据库并重新迁移了它,但没有任何效果
#config/routes.rb
Rails.application.routes.draw do
resources :items, only: [:new, :create], path_names: { new: "create" }
resources :welcome, path: "", only: :index do #-> url.com/
collection do
get :about #-> url.com/about
get :brandon #-> url.com/brandon
end
end
resources :users, only: [:index, :show] do #-> there may be a conflict with "/users/" as devise also uses "/users/" path
resources :items #-> url.com/users/:user_id/items
end
devise_for :users, controllers: { registrations: 'registrations' }
root "welcome#index"
end
如果它不起作用,我会删除它;您可能对正在进行的“裸体”声明有问题(始终尝试确定您的路由范围),或者您的生产环境中存在冲突的文件。我遇到了类似的情况。
使用作为设计选项为我解决了问题
devise_for :users, as: "unique_prefix", :controllers => { registrations: 'registrations' }
可能不相关,但您的前两个GET路由没有显示指向哪个控制器和操作,也可以尝试将您的根目录放在Desive_for route的下方。您好,Rich-感谢您的评论!我尝试使用您设置的路由,但再次出现相同的错误。不过,我非常感谢您关于设置路由的通知——“裸体声明”只是我开始学习如何编写路由的方式。这种方式当然更清楚:)