我跑3 RSpec的测试和我得到同样的错误这一个特定的路径:
Failure/Error: visit book_path
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"books"} missing required keys: [:id]
我的测试没有完全结束,所以我敢肯定,一些后者的代码可能不正确。 但我不能让我的访问路径行运行:
...
book = FactoryGirl.build(:book)
reviews = FactoryGirl.build_list(:review, 5, book: book)
visit book_path
reviews.each do |review|
expect(page).to have_content(review.rating)
expect(page).to have_content(review.body)
expect(page).to have_content(review.timestamp)
end
expect(page).to have_content('House of Leaves')
expect(page).to have_content('Mark Z. Danielewski')
expect(page).to have_content('Horror')
end
在我的控制,我已经展示定义为:
def show
@book = Book.find(params[:id])
@reviews = @book.reviews.order('created_at DESC')
@review = Review.new
end
而我的资源:
resources :books, only: [:index, :show, :new, :create] do
resources :reviews, only: [:show, :new, :create] do
end