Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveSupport encode_big_decimal_as_string

I would like to use the ActiveSupport option encode_big_decimal_as_string on one of my models. Should I put it in the model? Do I call this method on a model instance? Do I place this somewhere in config? What is an ActiveSupport option and how could I use it?

like image 206
Rob Avatar asked Jan 12 '23 21:01

Rob


1 Answers

Neither of these answers worked for me in Rails 4.0. Here is what works in Rails 4.0:

ActiveSupport::JSON::Encoding.encode_big_decimal_as_string = false

Add that line to your application config, like so:

# config/application.rb

...
module AppName
  class Application < Rails::Application
    ...
    ActiveSupport::JSON::Encoding.encode_big_decimal_as_string = false
    ...
  end
end

As @tyler-nguyen said, this is being deprecated in Rails 4.1, and extracted into this gem: ActiveSupport JSON Encoder. Refer to the gem documentation for configuration in 4.1.

like image 169
Nathan Wallace Avatar answered Jan 14 '23 09:01

Nathan Wallace