我需要一些帮助来获得Grape::API并使用Rails 4运行。我得到了一个Unable to autoload constant Base,尽管puts告诉我已经加载了该类。我做错了什么?
app/api/api.rb
class API < Grape::API
prefix 'api'
format :json
default_format :json
mount V1::Base # Everything loads perfectly until I add this line.
endapp/api/v1/base.rb
module V1
class Base < API
puts "=== DEBUG - in Base"
version 'v1', using: :path, vendor: 'orwapp', cascade: false
mount Users
end
end$ rspec spec/api
12:58:29 - INFO - Run all
12:58:29 - INFO - Running all specs
=== DEBUG - in Base
/dependencies.rb:481:in `load_missing_constant':
Unable to autoload constant Base,
expected /Users/martins/Work/myapp/app/api/v1/base.rb to define it (LoadError)
from /Users/martins/Work/myapp/app/api/api.rb:9:in `<class:API>'
from /Users/martins/Work/myapp/app/api/api.rb:3:in `<top (required)>'spec/api/users_spec.rb
describe 'GET /api/v1/users/:id', focus: true do
let(:user) { Fabricate :user }
it 'returns that specific user' do
get "/api/v1/users/#{ user.id }", {}, https_and_authorization
response.status.should eq 200
parse_response_for(:user)['email'].should eq user.email
end
end我正在使用的版本
$ ack grape Gemfile.lock
remote: git://github.com/intridea/grape.git
grape (0.9.1)
grape-entity (0.4.4)
grape-swagger (0.8.0)
grape
grape-entity发布于 2014-09-10 13:18:48
尝试让Base从Grape::API继承而不是API
module V1
class Base < Grape::API
...通过让它继承API,您将创建一个循环依赖关系:在解释器知道API的定义之前,它无法知道V1::Base的定义,但为此,它首先需要知道V1::Base的定义,等等。
发布于 2014-09-11 08:22:54
改为mount ::V1::Base修复了它。
https://stackoverflow.com/questions/25764244
复制相似问题