Rails路线冒泡了吗?

时间:2017-08-25 13:47:55

标签: ruby-on-rails ruby

以下案例是偶然的。它有效,但我不知道为什么。

在我的路线中,我有以下内容:

namespace :pro do
  resources :stores do
    resources :reports do
      resources :reviews, only: :index do
        collection do
          get :best
          get :chart
          post '/share', to: 'shared_links#create', defaults: { format: :json }
        end
      end
    end
  end
end


> bin/rake routes -g shared_links
Running via Spring preloader in process 70060
                         Prefix Verb URI Pattern                                           Controller#Action
share_pro_store_reports_reviews POST /pro/stores/:store_id/reports/reviews/share(.:format) pro/reports/shared_links#create {:format=>:json}

到目前为止,非常好。

错误地,创建了以下控制器:

# app/controllers/pro/shared_links_controller.rb

class Pro::SharedLinksController < Pro::ApplicationController
  # POST /pro/stores/:store_id/reports/reviews/share
  def create
  end
end

而不是

# app/controllers/pro/reports/shared_links_controller.rb

class Pro::Reports::SharedLinksController < Pro::ApplicationController
  # POST /pro/stores/:store_id/reports/reviews/share
  def create
  end
end

现在,奇怪的事情发生了。

development环境中,尽管出现了明显的错误,但一切正常:

Started POST "/pro/stores/hap0b/reports/reviews/share" for 127.0.0.1 at 2017-08-25 15:31:07 +0200
Processing by Pro::SharedLinksController#create as JSON

在非development环境中,行为是不同的,实际上,正如预期的那样:

Started POST "/pro/stores/hapba/reports/reviews/share" for 34.203.239.149 at 2017-08-25 13:00:40 +0000
ActionController::RoutingError (uninitialized constant Pro::Reports::SharedLinksController)
Did you mean?  Pro::SharedLinksController

我可以观察到的最后一件事是,在Pro::Reports::SharedLinksController#create中创建development时,它实际上是被调用的。{/ p>

所以这让我想知道是否会出现某种后备/泡沫逻辑。

0 个答案:

没有答案