Open sardaukar opened 10 years ago
Hmm, fixed this in another way. Feel free to close the issue, but would still like to know if this is possible. For future reference, I now have a BaseEntity class (since I always show ids and timestamps, useful for the links handling too):
class BaseEntity < Grape::Entity format_with(:iso_timestamp) { |dt| dt.iso8601 } expose :id with_options(format_with: :iso_timestamp) do expose :created_at expose :updated_at end expose :links, if: ->(obj, _) { obj.respond_to?(:links) } do |obj, _| obj.render_rel_links end end
And model classes that feature the "links" method include this module:
module RelLinkRenderer def render_rel_links [].tap do |arr| self.links.each_pair do |rel,href| arr << { rel: rel, href: href } end end end end
Contrived, but works :D
Hey again :)
I'm using this inside an AR model class:
And the entity associated to this model features:
The RelLinks class:
This is so that I can have a generic rel links presenter. However, my output is:
How can I get rid of the links/links duplication?
Thanks!