【问题标题】:Rails - Deploying to Heroku with duplicate routesRails - 使用重复路线部署到 Heroku
【发布时间】:2016-11-28 22:36:30
【问题描述】:

我正在将使用清除 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 文件

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

【问题讨论】:

    标签: ruby-on-rails heroku routes clearance


    【解决方案1】:

    这个问题与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? 为 true 时。

    你需要自己配置clearance来处理路由:

    config.routes = false
    

    【讨论】:

    • config.routes 已在初始化程序中设置为“false”。
    • @got2jam 读了你的回答,很奇怪,但很高兴你能正常工作。
    • 是的,我将对此进行更多研究。 Clearance 建议您关闭用户生成路线,这样我才能做到这一点。我正在学习 Rails 以获得快速而肮脏的 MVP,但有点被它迷住了,所以我会更多地潜入路线谢谢你的帮助
    【解决方案2】:

    在查看 gems GitHub 之后,看起来我早先对路由进行了倾斜,即使在初始化程序中将 config.routes 设置为 false,在生产中生成的资源中也会产生冲突。

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

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 2016-11-19
      • 2017-02-02
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2023-03-31
      相关资源
      最近更新 更多