1

我有一个联系人模型的葡萄实体,它两次引用用户模型:

class Contact < ApplicationRecord
  belongs_to :user, foreign_key: :user_id
  belongs_to :contact, class_name: 'User', foreign_key: :contact_id

  def entity
    Entity.new(self)
  end

  class Entity < Grape::Entity
    expose :contact do
      expose :id
      expose :user, as: :inviter, merge: true, using: User::Entity
      expose :contact, as: :invitee, merge: true, using: User::Entity
      expose :status
    end
  end
end

当我得到一个提供联系人的端点时,我有以下错误

ArgumentError:
   wrong number of arguments (given 3, expected 0)
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure/output_builder.rb:53:in `block in merge_strategy'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure/output_builder.rb:19:in `merge!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure/output_builder.rb:19:in `add'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:62:in `block (2 levels) in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:108:in `block in with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/options.rb:102:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:107:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:61:in `block (2 levels) in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:108:in `block in with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/options.rb:102:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:107:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/entity.rb:473:in `serializable_hash'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/formatter/json.rb:6:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:44:in `block in build_formatted_response'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:44:in `collect'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:44:in `build_formatted_response'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:28:in `after'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:34:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:31:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:31:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/error.rb:34:in `block in call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/error.rb:33:in `catch'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/error.rb:33:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/endpoint.rb:224:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/endpoint.rb:218:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router/route.rb:72:in `exec'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:119:in `process_route'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:74:in `block in identity'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:93:in `transaction'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:72:in `identity'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:57:in `block in call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:135:in `with_optimization'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:56:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/api.rb:119:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/api.rb:45:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/api.rb:40:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/etag.rb:25:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/conditional_get.rb:25:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:36:in `call_app'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `block in call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/engine.rb:522:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:124:in `request'
# ./spec/requests/contacts_spec.rb:39:in `block (4 levels) in <top (required)>'

如何使其在联系人实体中包含邀请者和被邀请者的用户实体?

4

0 回答 0