sebastianedwards / collection-json Goto Github PK
View Code? Open in Web Editor NEWLightweight gem for building Collection+JSON responses.
License: Other
Lightweight gem for building Collection+JSON responses.
License: Other
One of the accepted extensions of CJ is inline links. I'd love to see this feature in, since I'll be needing it a lot.
I can take care of it and send a PR.
Hi,
I'm not sure it's a collection-json bug or a rails one.
When I try to convert my collection to json it raises undefined method `merge' for []:Array.
I've managed to find that the problem is in the .to_json method of the CollectionJSON::Attribute class. More precisely with the args argument.
If I convert this:
def to_json(*args)
to_hash.to_json(args)
end
To this:
def to_json(*args)
to_hash.to_json
end
No more problems.
At the same time, if I'm calling JSON.generate(collection.to_hash) in my code instead of collection.to_json it's working without any problem.
collection.to_json is working great in irb.
So I suppose there is a monkey patch clash somewhere with Rails.
Thanks
EDIT:
Looking more in depth into it, the optional parameter to to_json must be hash-like. You are using a splat so here it's an array and it fails.
Converting the .to_json method to something like that fixed the problem in rails:
def to_json(args = {})
to_hash.to_json(args)
end
I like to use this gem in a project, but see no official license. Is this free software? ;)
The output I get when I build a document omits the version attribute.
it would be good to have
collection = CollectionJSON.generate_for('/friends/') do |builder|
builder.set_version "1.0"
...
to output
{ "collection" :
{
"version" : "1.0",
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.