0

我正在将使用清除 gem 的 Rails 应用程序部署到 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 文件

路由.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
4

2 回答 2

1

这个问题与clearance宝石有关。

我对 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
于 2016-11-28T22:46:40.347 回答
0

在查看 gems GitHub之后,看起来我之前已经搜索了路由,即使 config.routes 在初始化程序中设置为 false,但在生产中生成的资源中还是会产生冲突。

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

于 2016-11-29T03:43:12.373 回答