I have a representer for my Location model. A location has many Observations. I would like a link to each observation, like below:
{
id: 1,
latitude: 40,
longitude: 50,
},
My representer is below:
#This is decorator-style roar. To use, return LocationRepresenter.new(Location)
class LocationRepresenter < Representable::Decorator
include Roar::Representer::JSON::HAL
property :id
property :latitude
property :longitude
links :observation do
represented.observation.map {|o| {rel: nil, href: "/observation/#{
o.id}"}}
end
end #class LocationRepresenter
when I run this, I get the following error:
13:45:42 web.1 | Unexpected error while processing request: undefined method `rel' for nil:NilClass
13:45:42 web.1 | /home/luke/.rvm/gems/ruby-2.0.0-p247/gems/roar-0.12.0/lib/roar/representer/json/hal.rb:139:in `rel'
13:45:42 web.1 | /home/luke/.rvm/gems/ruby-2.0.0-p247/gems/roar-0.12.0/lib/roar/representer/feature/hypermedia.rb:113:in `add'
I've asked on IRC, but I can't understand what I'm doing wrong. Any help greatly appreciated!