`add_route':无效的路由名称,已经在使用:'new_user_session'(ArgumentError)

问题描述 投票:3回答:2

我无法让我的应用程序通过Heroku在生产环境中运行。它是开发中可以完全使用的应用程序。

我在SO上研究了这个问题,但是许多解决方案是由于devise_for中的routes.rb重复。我的应用程序没有这个问题,而且我很难找出发生此重复的地方。

这是完整的错误消息:

/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

我已经更新了我的宝石,删除了数据库并重新迁移它,但没有任何效果。

ruby-on-rails ruby heroku routes precompile
2个回答
0
投票
#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

如果不起作用,我将删除它;您可能对自己的“裸”声明有疑问(始终尝试在resources周围确定路线范围),或者在生产环境中有冲突的文件。


0
投票

我也遇到类似的情况。devise_for的as选项的使用为我解决了。

resources
© www.soinside.com 2019 - 2024. All rights reserved.