简体   繁体   中英

ActionController::UrlGenerationError: error No routes matches

I get the below error ActionController::UrlGenerationError.

ActionController::UrlGenerationError:
       No route matches {:action=>"/accounts/100", :controller=>"accounts"}

Below is my code which throws this error.

  it "can find an account" do
  Account.should_receive(:find, with: {id: 2055, authorization: @auth}

  get "/accounts/100", nil, {"AUTH_TOKEN" => @auth}

  hashed_response = {
    "@type" => "test",
    "createdAt" => "2014-07-24T15:26:49",
    "description" => "Something about test",
    "disabled" => false
  }
  expect(response.status).to eq 200    
  expect(response.body).to eq(hashed_response.to_json);

end

I did a google on this and came to know that there is no routes defined for this. Below is my config/routes.rb file

Rails.application.routes.draw do
   resources :accounts do
      resources :holders
   end
end

I presume this error is coming from a controller spec? If so, you simply use a symbol representing the action you want to call, not the URL itself.

eg. this is a show action, so you would use:

get :show, id: 100

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM