I use default JSON serialization for a model with the number of decimal and integer attributes. Example:
{ "user": { "id": 1234, "rating": "98.7" } }
Pay attention to adding quotes around the value of "rating". This causes the deserialization library I use to incorrectly treat them as strings (instead of decimals). Can Rails set to not use quotation marks for all decimals?
Edit:
I'm on Rails 3.0.7 and Ruby 1.9.2, if that matters.
Edit:
Terminal:
rails g model user rating:decimal rake db:migrate
Console:
user = User.create(rating: 98.7) user.to_json
ruby-on-rails
Kevin Sylvestre May 25 '11 at 18:02 2011-05-25 18:02
source share