Rails - 使用重复路由部署到 Heroku

Rails - Deploying to Heroku with duplicate routes

我正在部署我的 Rails 应用程序,该应用程序使用许可 gem 到 Heroku。在开发中一切正常,但我 运行 遇到了 gem 生成的路由问题。

尝试部署到 Heroku 时,出现错误...

ArgumentError: Invalid route name, already in use: 'sign_in'


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:
remote:        http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

我没有看到限制重复项的位置或使用我的任何资源生成重复项的位置:

请参阅下面的 routes.rb 文件

Routes.rb

Rails.application.routes.draw do

  resources :passwords, controller: "clearance/passwords", only: [:create, :new]
  resource :session, controller: "clearance/sessions", only: [:create]

  resources :users, controller: "clearance/users", only: [:create] do
    resource :password,
      controller: "clearance/passwords",
      only: [:create, :edit, :update]
  end

  get "/sign_in" => "clearance/sessions#new", as: "sign_in"
  delete "/sign_out" => "clearance/sessions#destroy", as: "sign_out"
  get "/sign_up" => "clearance/users#new", as: "sign_up"

  get 'newSignUp', to: 'signups#new'
  post 'newSignUp', to: 'signups#create'

  get 'newTrip', to: 'trips#new'
  post 'newTrip', to: 'trips#create'

  get 'trips/:id/send_itinerary' => 'trips#send_itinerary', as: :trips_send_itinerary



  root 'static_pages#home'
  get 'static_pages/home'
  get 'static_pages/help'
  get 'static_pages/about'
  get 'static_pages/contact'


  resources :signups
  resources :tripitems
  resources :trips

end

此问题与 clearance gem。

我对 gem 不是很熟悉,所以和往常一样,我查看了 github 并发现了以下内容:

# config/routes.rb
if Clearance.configuration.routes_enabled?
  Rails.application.routes.draw do
    resources :passwords,
      controller: 'clearance/passwords',
      only: [:create, :new]

    resource :session,
      controller: 'clearance/sessions',
      only: [:create]

    resources :users,
      controller: 'clearance/users',
      only: Clearance.configuration.user_actions do
        resource :password,
          controller: 'clearance/passwords',
          only: [:create, :edit, :update]
      end

    get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
    delete '/sign_out' => 'clearance/sessions#destroy', as: 'sign_out'

    if Clearance.configuration.allow_sign_up?
      get '/sign_up' => 'clearance/users#new', as: 'sign_up'
    end
  end
end

这基本上是在为您创建相同的路由,前提是配置 routes_enabled? 为真。

您需要如下配置clearance来自己处理路由:

config.routes = false

在查看了 gems GitHub 之后,看起来我早先搜索了路由,即使 config.routes 在初始化程序中设置为 false,在生成的资源中仍然存在冲突生产。

我最后删除了倾斜的路线并使 config.routes=true。