0

我要回到一个我有一段时间没看过的 Rails 项目了。这可能是我看不到的非常简单的事情。

对于常见问题解答,我的应用程序有一个大部分静态视图。当我耙路线时,它显示得很好:

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)>'

下面是我的配置/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
4

1 回答 1

3

该错误不是由规范引起的,而是由在第 130 行faq_path从内部调用的缺少路由引起的(参见规范回溯)。faq.html.erb

于 2013-10-03T16:26:00.723 回答