Adding a dynamic set of links based on a field value

13 views
Skip to first unread message

Daniel Doubrovkine

unread,
Mar 16, 2016, 1:21:14 PM3/16/16
to Roar
I have a collection of image_versions, and I'd like to generate a _link for each. 

For example if image_versions is ['small', 'large'] I'd like to have an image:small and an image:large in my _links collection. 

I can easily add an images collection by presenting the image_versions array with a custom presenter, but I can't figure out how to add those as _links.  

What's the best way to achieve that?

Thx
dB.

Josh Cohen

unread,
Mar 16, 2016, 1:58:06 PM3/16/16
to roar...@googlegroups.com
Are you you building a server using representable?
I think you can use the variable 'represented' in a link definition to access the represented resource.  

--
You received this message because you are subscribed to the Google Groups "Roar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Josh Cohen  jos...@gmail.com | @joshco | LinkedIn | GitHub  | OSDI opensupporter.org

Looking for a contract developer to work on APIs, integrations, servers, WordPress?  Hire me!
"If [OSDI] succeeds, it could usher in the next chapter in political technology." - Washington Post

Daniel Doubrovkine

unread,
Mar 16, 2016, 4:44:28 PM3/16/16
to roar...@googlegroups.com
But the problem I am trying to solve is how to dynamically define a link name and have a variable number of links. This won't work since it's evaluated at class definition time:

        class ImagePresenter
            property :image_versions, type: Array

           # we want this on an instance
           image_versions.each do |image_version|
              link "image:#{image_version}" do
              end
           end
       end

Josh Cohen

unread,
Mar 18, 2016, 9:30:52 PM3/18/16
to roar...@googlegroups.com
Hmm that is a good question.  I'll poke around.
Reply all
Reply to author
Forward
0 new messages