ruby-grape / ruby-grape/grape-entity
present_collection issue
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
Reading http://www.rubydoc.info/github/intridea/grape-entity/Grape%2FEntity.present_collection and I think there might be a bug in documentation.
Definition
class Users < Grape::Entity
present_collection true
expose :items, as: 'users', using: API::Entities::Users
end
Usage
module API
class Users < Grape::API
version 'v2'
# this will render { "users" : [ { "id" : "1" }, { "id" : "2" } ], "version" : "v2" }
get '/users' do
@users = User.all
present @users, with: API::Entities::Users
end
end
Shouldn't expose :items, as: 'users', using: API::Entities::Users have singular class name?
Now I get stack level too deep error, but when I change from Users to User, it returns null.
Please advise. Thank you
My code:
api/events.rb
desc 'Recently booked'
get 'recently_booked' do
events = Event.active
present events, with: API::Entities::Events
end
api/entities/events.rb
module API
module Entities
class Events < Grape::Entity
present_collection true
expose :location
expose :events, using: API::Entities::Events
end
end
end

Ruby: 2.3.0
Rails: 4.2.5.1
Gems: 2.5.1
$ bundle | grep 'grape'
Using grape-entity 0.4.8
Using grape 0.14.0
Using grape-swagger 0.10.4
Using grape-kaminari 0.1.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with api/events.rb and api/entities/events.rb, then read the present_collection and expose behavior used by Grape::Entity. Reproduce the recently_booked endpoint with the shown Events entity and compare the recursive Users/Events examples. Done means the collection declaration and entity class naming are clarified, with the stack overflow and null response behavior accounted for.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100