没有路由匹配,rails使用错误的控制器?

时间:2013-10-03 16:20:03

标签: ruby-on-rails rspec controller

我要回到一段时间以来我没有看过的铁轨项目。这可能是我看不到的非常简单的事情。

我的应用常见问题解答主要是静态视图。当我耙路线时,显示正常:

faq        /faq(.:format)     base_pages#faq

我设置了一个非常简单的rspec测试,以确保它正常工作:

describe "BasePages" do
    describe "FAQ" do
        before { visit faq_path }

        it { should have_selector('h1', text: "FAQ") }
    end
end

当我运行测试时,我收到此错误:

  1) BasePages FAQ 
     Failure/Error: before { visit faq_path }
     ActionView::Template::Error:
       No route matches {:action=>"show", :controller=>"festivals", :id=>nil}
     # ./app/views/base_pages/faq.html.erb:130:in `_app_views_base_pages_faq_html_erb___446447898979674530_70112514729120'
     # ./spec/requests/base_pages_spec.rb:105:in `block (3 levels) in <top (required)>'

以下是我的config / routes.rb:

Cif::Application.routes.draw do

  resources :posts

  match '/news', to: 'posts#index'

  get "payment/cancel"

  get "payment/success"

  post "payment/record"

  post "stripe_events/record"

  resources :submissions do
    resources :links, only: [:new, :create, :edit, :update, :destroy]
    resources :performers, only: [:new, :create, :edit, :update, :destroy]
    resources :charges, only: [:new, :create]
  end

  resources :festivals, only: [:index, :show]
  resources :submissions, only: :index
  resources :admin, only: :index
  resources :curator, only: :index

  devise_for :users

  namespace :admin do
    resources :users, only: [:index, :show, :edit, :update]
    resources :submissions do
      member do
        get 'notify'
        get 'format_for_wordpress'
      end
    end
    resources :festivals do
      resources :categories, except: :index
    end
  end

  namespace :curator do
    resources :submissions, only: [:index, :show] do
      resources :assessments, only: [:new, :edit, :create, :update]
    end
  end

  root to: 'base_pages#home'

  match '/about',   to: 'base_pages#about'
  match '/contact', to: 'base_pages#contact'
  match '/faq',     to: 'base_pages#faq'
  match '/ping',    to: 'base_pages#ping'
  match '/confirmed',    to: 'base_pages#confirmed'

end

1 个答案:

答案 0 :(得分:3)

错误不是由规范中的faq_path造成的,而是来自faq.html.erb内部第130行的遗失路线(请参阅规范回溯)。