Altonymous
Altonymous

Reputation: 783

Rails routes issue with controller testing

I'm at a loss as to what I'm doing wrong here. Anyone have any insight?

Here's my routes.rb

resources :accounts do
    collection do
        get "search/:term/:offset/:limit.:format", :action => "search", :constraints => { :offset => /\d+/, :limit => /\d+/ }
    end
end

Here's my rake routes output...

GET    /accounts/search/:term/:offset/:limit.:format    {:offset=>/\d+/, :action=>"search", :controller=>"accounts", :limit=>/\d+/}

Here's my test line...

get :search, :term => "Test", :offset => 0, :limit => 2

Here's my error...

ActionController::RoutingError: No route matches {:term=>"Test", :action=>"search", :controller=>"accounts", :offset=>0, :limit=>2}

Any ideas?

Thanks in advance!

Upvotes: 1

Views: 287

Answers (1)

Altonymous
Altonymous

Reputation: 783

I found the issues...

1) It is expecting to match on strings so instead of

:offset => 0, :limit => 2

it should be

:offset => '0', :limit => '2'

2) :format was not optional. I chose to make it an optional param, but if you encounter this you will have to pass format along if you don't make it optional.

Upvotes: 2

Related Questions