intridea/grape — Issue #75: Problem with entity in using :with
Author: amrnt
Created: 2011-11-21 00:04:01+00:00
State: open

Assume I have 2 models: User and Preference. User `has_one` preference.

And here's Grape entities:

```ruby
module Entities
class PreferenceEntity < Grape::Entity
expose :logo, :background_color
end

class UserEntity < Grape::Entity
expose :full_name
expose :email
expose :preference, :as => :preferences, :using => PreferenceEntity
end
end
```

Now, with

```ruby
get "me" do
present current_user, :with => Entities::UserEntity
end
```

Throws this error:

```json
{
error: "wrong number of arguments(0 for 2)",
backtrace: [
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/entity.rb:145:in `autoload'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/entity.rb:145:in `value_for'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/entity.rb:124:in `block in serializable_hash'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/entity.rb:123:in `each'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/entity.rb:123:in `inject'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/entity.rb:123:in `serializable_hash'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:55:in `block in as_json'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:78:in `check_for_circular_references'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:54:in `as_json'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `block in as_json'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `each'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `map'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `as_json'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:47:in `block in encode'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:78:in `check_for_circular_references'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:46:in `encode'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:31:in `encode'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/activesupport-3.1.1/lib/active_support/core_ext/object/to_json.rb:20:in `to_json'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/multi_json-1.0.3/lib/multi_json/engines/json_gem.rb:17:in `encode'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/multi_json-1.0.3/lib/multi_json.rb:72:in `encode'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:115:in `encode_json'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/formatter.rb:79:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/formatter.rb:79:in `block in after'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/formatter.rb:78:in `collect'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/formatter.rb:78:in `after'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:26:in `call!'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:19:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:25:in `call!'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:19:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:25:in `call!'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:19:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/error.rb:44:in `block in call!'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/error.rb:43:in `catch'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/error.rb:43:in `call!'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/middleware/base.rb:19:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bundler/gems/grape-ece183048418/lib/grape/api.rb:32:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/warden-1.1.0/lib/warden/manager.rb:35:in `block in call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/warden-1.1.0/lib/warden/manager.rb:34:in `catch'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/warden-1.1.0/lib/warden/manager.rb:34:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:195:in `context'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:190:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/rack-1.3.5/lib/rack/reloader.rb:44:in `call'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run_machine'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/controllers/controller.rb:86:in `start'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/runner.rb:185:in `run_command'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/lib/thin/runner.rb:151:in `run!'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/gems/thin-1.3.1/bin/thin:6:in `'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bin/thin:19:in `load'",
"/Users/amr/.rvm/gems/ruby-1.9.2-p290@api-new/bin/thin:19:in `

'"
]
}
```