Try:
get 'beat' => 'heart_beat#beat', as: => 'beat'
Note for others: In Rails 4, the name of the controller object in a route must be in snake_case for multiple word controllers.
Ex:
get 'action' => 'snake_case_controller_name#action'
Pregunta
I have a route that matches:
get 'beat' => 'heartbeat#beat', as: => 'beat'
#=> api_v1_beat GET /api/v1/beat(.:format) api/v1/heartbeat#beat
I then have a controller, exceptionally basic!
module Api
module V1
class HeartBeatController < BaseController
def beat
respond json: {}, status: 200
end
end
end
end
Concept is you would ping this every 15-30 seconds to see if were alive.
Now I need a test for this,
require 'spec_helper'
describe Api::V1::HeartBeatController do
context "200" do
it "should ping the heartbeat and return 200" do
get :beat
expect(response.code).to eql '200'
end
end
end
But it fails:
Failure/Error: get :beat
ActionController::UrlGenerationError:
No route matches {:action=>"beat", :controller=>"api/v1/heart_beat"}
uh ??? Its pretty obvious what it states, but maybe I am missing something so rudimentary and basic?
Solución
Try:
get 'beat' => 'heart_beat#beat', as: => 'beat'
Note for others: In Rails 4, the name of the controller object in a route must be in snake_case for multiple word controllers.
Ex:
get 'action' => 'snake_case_controller_name#action'
Otros consejos
Write a routing test also:
describe HeartBeatController do
describe "routing" do
it "routes to #beat" do
get("/beat}").should route_to("api/v1/heart_beat#beat")
end
end
end