1

我正在做作业,但我对非 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 出了点问题。如何解决这个问题?

4

1 回答 1

2

你的路线应该是这样的

resources :movies do
    get 'search_similar_movies', :on => :collection
end

或者

match 'movies/search_similar_movies/:search_terms' => 'movies#search_similar_movies', :via => :get

于 2012-04-04T10:34:05.003 回答