我正在做作业,但我对非RestFul路线有问题。 我的规格是:
require 'spec_helper'
describe MoviesController do
describe 'searching TMDb' do
before :each do
@fake_results = [mock('Movie'), mock('Movie')]
end
it 'should call the model method that performs TMDb search' do
Movie.should_receive(:find_in_tmdb).with('Star Wars').
and_return(@fake_results)
get :search_similar_movies, { :search_terms => 'Star Wars' }
end
end
end
在config / routes.rb中我有:
resources :movies
'movies/search_similar_movies/:search_terms'
但是当我运行自动测试时,它会给我一个以下开头的错误:
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/mapper.rb:181:in `default_controller_and_action': missing :action (ArgumentError)
显然有问题的是config / routes.rb。怎么解决这个问题?
答案 0 :(得分:2)
您的路线应该是
resources :movies do
get 'search_similar_movies', :on => :collection
end
或
match 'movies/search_similar_movies/:search_terms' => 'movies#search_similar_movies', :via => :get