Closed mustela closed 8 years ago
Wrong Roar, and wrong Representable! :grimacing:
Get roar/master
, I'll push 1.1 as soon as I get more feedback! :beers:
Great! Its partially working now because relathionships are not being loaded.
This is the json
{
"data": {
"type": "organization",
"attributes": {
"name": "New org",
"description": "My org description"
},
"relationships": {
"organization_type": {
"data": { "type": "organization_type", "id": "5f7118bd-afd9-4943-a101-2d5d1b7e1143" }
}
}
}
}
And the decorator
require "roar/json/json_api"
require "json"
class OrganizationDecorator < Roar::Decorator
include Roar::JSON::JSONAPI
type :organizations
# attributes: {}
property :id
property :name
# relationships
has_one :organization_type, populator: ::Representable::FindOrInstantiate do
type :organization_types
property :id
property :name
end
end
And the result
#<Organization:0x007fc8993c6c20
id: nil,
name: "",
logo_url: nil,
website_url: nil,
billing_user_id: nil,
organization_type_id: nil,
tags: nil,
description: nil,
social: {},
founded: nil,
slug: nil,
created_at: nil,
updated_at: nil,
deleted_at: nil>
As you can see the organization type hasn't ben loaded organization_type_id: nil,
Its working now :), thanks!
Hi there!
I'm trying to parse the following json
So I have an Organization Decorator
Organization
is a rails model, and then I'm trying to parse itBut I can't make it works, I keep getting:
undefined method
[]' for nil:NilClass`What I'm doing wrong?
Thanks!