rails / activesupport-json_encoder Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Bundler could not find compatible versions for gem
"activesupport":
In Gemfile:
activesupport-json_encoder was resolved to 1.0.0, which
depends on
activesupport (< 5.0, >= 4.1.0.beta)
rails (~> 5.1.4) was resolved to 5.1.4, which depends on
activesupport (= 5.1.4)
spring was resolved to 2.0.2, which depends on
activesupport (>= 4.2)
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 5.1.4)
Could not find gem 'rails (~> 5.1.4)' in any of the sources.
Here's an example:
https://gist.github.com/msavy/884642ff7a8b835a4d9e
Note, I'm not using Rails. It works nicely if the objects extend hash, as in your tests, but not if you're just implementing as_json(options={})
$ bundle exec ruby ticket.rb
# to_json
{"obja":{"whynot":"zoidberg","this":"string"}}
# JSON.pretty_generate
/Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:285:in `generate': only generation of JSON objects or arrays allowed (JSON::GeneratorError)
from /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:285:in `pretty_generate'
from ticket.rb:28:in `<main>'
Side-note: Apologies for initially empty ticket as I lost the focus on the input box without noticing, so when I hit enter I posted the new issue before I was finished!
I'm trying to add this gem so I can get the encode_big_decimal_as_string
option back, but when I try to bundle install I get:
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
activesupport-json_encoder was resolved to 1.0.0, which depends on
activesupport (< 5.0, >= 4.1.0.beta)
Seems like it's set to require Rails 4. Is there another solution for Rails 5?
I saw in gemspec that AJE does not work with rails >5.0.
Have you guys stoped with this gem ?
Since encode_big_decimal_as_string was deprecated in Rails 5, we now get an error message:
/vagrant/config/environment.rb:4:in `<top (required)>': undefined method `encode_big_decimal_as_string=' for ActiveSupport:Module (NoMethodError)
from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:302:in `require'
from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:302:in `block in require'
from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:268:in `load_dependency'
from /var/lib/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies.rb:302:in `require'
from /vagrant/config.ru:3:in `block in <main>'
from /home/vagrant/.bundler/ruby/2.2.0/rack-ea2ed578c368/lib/rack/builder.rb:55:in `instance_eval'
from /home/vagrant/.bundler/ruby/2.2.0/rack-ea2ed578c368/lib/rack/builder.rb:55:in `initialize'
Code:
ActiveSupport.encode_big_decimal_as_string = false
I try to use this to get custom json & always get "stack level too deep" error
I try to use irb like
require 'active_support'
ActiveSupport.version #=> version : 4.1.6
require 'active_support/json/encoding/active_support_encoder'
#same as README demo
class Money
def initialize(dollars, cents)
@dollars = dollars
@cents = cents
end
def as_json(options = nil)
self
end
def encode_json(encoder)
if @cents.to_i < 10
"#{@dollars.to_i}.0#{@cents.to_i}"
else
"#{@dollars.to_i}.#{@cents.to_i}"
end
end
end
{ price: Money.new(0,10) }.to_json #=> stack level too deep
can you fix it? & my ruby : ruby 2.1.2
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.