Expose default value doesn't work for me
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the default value documentation linked in the issue and reproduce the behavior using the shown ProductEntity and grape-entity version 0.10.2. Check how short_description and an array default are serialized when the source value is absent; done means the configured defaults appear in the resulting hash or the issue is clarified with the required usage or version behavior.
Written by the indexing model from the issue text.
Description
Hi,
First of all thanks for the amazing work!
I am using grape entity to serialize ActiveRecord (Rails) objects to a hash, using .respresent(object)
My grape entity looks like this:
class Entities::ProductEntity < Grape::Entity
expose :platform_id, as: :id
expose :name
expose :visible
expose :main_image
expose :url
expose :short_description, default: ''
expose :brand_id
expose :category_ids
expose :relevant_product_ids
def brand_id
object.brand&.platform_id if object.respond_to?(:brand)
end
def category_ids
object.categories&.pluck(:platform_id) if object.respond_to?(:categories)
[]
end
def relevant_product_ids
object.relevant_products&.pluck(:platform_id) if object.respond_to?(:relevant_products)
[]
end
end
The default option on short_description doesn't work, neither did it work if i tried to use it in another entity with default: []
Am i doing something wrong? Or am I on an old version?
I am using https://github.com/ruby-grape/grape-entity#default-value this syntax, and am on grape-entity version 0.10.2
Hope you have some time to help me out, but no worries if not.
Thanks in advance
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
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.
More from ruby-grape/grape-entity
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ruby-grape/grape-entity#386 · 7 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#382 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#380 ·
-
Truncate Formatter Open
Difficulty 1/5 1-3 hours Newbie friendliness 45/100
ruby-grape/grape-entity#372 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
ruby-grape/grape-entity#370 ·
All issues in ruby-grape/grape-entity
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TheOdinProject/curriculum#31408 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
notch8/utk_knapsack#148 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Homebrew/homebrew-cask#288729 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100