`add_route':无效的路线名称,已在使用中:' new_user_session' (引发ArgumentError)

时间:2016-01-21 20:12:14

标签: ruby-on-rails ruby heroku routes precompile

我无法通过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

我更新了我的宝石,删除了数据库并重新迁移它无效。

2 个答案:

答案 0 :(得分: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调整路径范围),要么生产环境中存在冲突的文件。

答案 1 :(得分:0)

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

devise_for :users, as: "unique_prefix", :controllers => { registrations: 'registrations' }