Tag: json

Ruby objects and JSON serialization (without Rails)

I’m trying to understand the JSON serialization landscape in Ruby. I’m new to Ruby. Is there any good JSON serialization options if you are not working with Rails? That seems to be where this answer goes (to Rails) How to convert a Ruby object to JSON The json gem seems to make it look like […]

Ruby JSON gem (1.1.3) failed to install

This is the error I got: MacBook-Pro:myapp marcamilly$ gem install json -v 1.1.3 Building native extensions. This could take a while… ERROR: Error installing json: ERROR: Failed to build gem native extension. /Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb creating Makefile make gcc -I. -I/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-darwin10.4.0 -I/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 […]

Error in JSON Ruby Gem – Ubuntu 11.04

Hello the clever people of Stackoverflow. I am trying to right a little JSON script. But the JSON Gem does not seem to be working. Just by having the code: require ‘rubygems’ require ‘json’ I get the error: ./json.rb:5: undefined method `search’ for nil:NilClass (NoMethodError) from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’ from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require’ from places.rb:2 I don’t […]

Class Method in 'as_json' not working for index action

New to Ruby/Rails, so bear with me. I have a ActiveRecord model class Status. I’m rendering it as json to be used in a mobile web application. It consists of an id, name, code, and back_color (in decimal color). I needed to do a color conversion from BGR decimal to RGB hex, so I decided […]

Prevent json/pure from loading in Rails

I’m writing a Rails application, using the ‘json‘ gem, and its behavior where it can switch between the ‘json/pure’ and ‘json/ext’ implementations is causing problems. Specifically, sometimes a gem introduces a line like require ‘json/pure’ When that happens, JSON.parser and JSON.generator switch to the slow, ruby-based version globally. Then every call to JSON.parse and JSON.generate […]

josevalim / active_model_serializers controller argument error

I am playing with Jose Valim’s active_model_serializers Gem. I am attempting to call a custom serializer in my controller, and it looks like :json is not using the ActiveModel::ArraySerializer as it should. When I define the default active_model_serializer in the controller, the serializer works fine; however, when I call a custom one like this in […]

I cant install oj ruby gem on windows 7 64

I tried to install oj ruby gem gem install oj -v ‘1.3.5’ Here’s the output log C:/Ruby192/bin/ruby.exe extconf.rb Creating Makefile for ruby version 1.9.2 <<<<< creating Makefile make C:/Ruby192/bin/ruby -e “puts ‘EXPORTS’, ‘Init_oj'” > oj-i386-mingw32.def gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DRUBY_TYPE=ruby -DRUBY_RUBY -DRUBY_VERSION=1.9.2 -DRUBY_VERSION_MAJOR=1 -DRUBY_VERSION_MINOR=9 -DRUBY_VERSION_MICRO=2 -DHAS_RB_TIME_TIMESPEC=0 -DHAS_ENCODING_SUPPORT=1 -DHAS_NANO_TIME=1 -DHAS_RSTRUCT=1 -DHAS_IVAR_HELPERS=1 -DHAS_EXCEPTION_MAGIC=0 -DHAS_PROC_WITH_BLOCK=1 -DHAS_TOP_LEVEL_ST_H=0 […]

controlling sort order of json output in Ruby on Rails (Ruby 1.8)

Is there any way to convert a ruby array/hash structure to JSON AND specify the output order of the elements? Having the actually order of the elements vary is not functionally important, BUT it just makes debugging tough… It would be nicer if I could somehow specify the tag order to the json output, so […]

Can't install json gem in Windows

I tried to install the json gem on Windows. I installed DevKit. I get the following error below. Any suggestions? This question JSON Gem will not install (Windows) suggests installing DevKit and also try using json_pure. I did both. The problem is that my bundle install is trying to install json and won’t proceed until […]

Rails bundle install – failed to build gem native extension for JSON

I was trying to fix a strange problem in Rails so I resorted to uninstalling all the gems (using a command found here: http://geekystuff.net/2009/01/14/remove-all-ruby-gems/) and then running bundle install. The removal was successful, but when I ran bundle install, I got the following error: Installing activeresource (3.2.13) Using bundler (1.3.5) Installing rack-ssl (1.3.3) Installing json […]

Ruby is the best programming language in the world - Ruby on Rails.