我很难通过Heroku让我的应用程序在生产中运行。它是一个在开发中完全工作的应用程序。
我研究了这个问题,但是很多解决方案都是因为它们的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

我已经更新了我的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

如果它不起作用,我将删除它;您要么对所做的“裸体”声明有问题(总是尝试在resources周围确定您的路由范围),要么您的生产环境中有一个冲突的文件。

关于ruby-on-rails - `add_route':无效的路由名称,已在使用中:'new_user_session'(ArgumentError),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34933396/

10-09 05:54