rails 4 + grape 0.7.1 按照官方的 guide 做,只是改了改一些命名! 试过
http://localhost:3000/api/nodes
http://localhost:3000/api/nodes.json
但是怎么都访问不了 API,出现错误No route matches [GET] "/api/nodes"
请教下,哪里出现错误了?
以下是代码
app
/api
/mywy
api.rb
entities.rb
helper.rb
api.rb
require "entities"
require "helpers"
module Mywy
class API < Grape::API
prefix "api"
version "v1"
format :json
resource :nodes do
desc "Return list of nodes"
get do
@nodes = Node.all
present @nodes, with: APIEntities::Topic
end
end
end
end
route.rb
Mywy::Application.routes.draw do
mount Mywy::API => '/'
...
end
application.rb
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]