Giter Club home page Giter Club logo

collection-json's People

Contributors

carlesjove avatar mustmodify avatar pcboy avatar sebastianedwards avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

collection-json's Issues

.to_json raising "undefined method `merge' for []:Array" in rails 3.1

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

license?

I like to use this gem in a project, but see no official license. Is this free software? ;)

No option to set version in the collection

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",
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.