ruby-on-rails - 将大量美元值输入到 Rails 货币对象中

标签 ruby-on-rails postgresql ruby-on-rails-4 money-rails

我已经构建了一个运行 Rails 4.1 和 ruby​​ 1.9.3 的应用程序,它使用 money-rails gem 。当我在表单字段中输入较大的美元值并将其保存到我的 PG 数据库时,我遇到了问题。错误如下:

PG::NumericValueOutOfRange: ERROR: value "9900000000" is out of range for type integer

PG docs显示整数的最大值为+2147483647。我希望能够使用钱轨 gem ,但能够输入更大的数字。

就解决方案而言,我知道 PG 中的列类型应该是 bigint,但是我不知道如何使 Money-rails 支持将数字存储为 bigint 而不是整数。

最佳答案

这里是money-rails README它表明您可以将其配置为使用其他数据类型:

# Default ActiveRecord migration configuration values for columns:
#
# config.amount_column = { prefix: '',           # column name prefix
#                          postfix: '_cents',    # column name  postfix
#                          column_name: nil,     # full column name (overrides prefix, postfix and accessor name)
#                          type: :integer,       # column type
#                          present: true,        # column will be created
#                          null: false,          # other options will be treated as column options
#                          default: 0
#                        }

请注意,有一个 type: :integer 选项。尝试将其更改为 :bigint

关于ruby-on-rails - 将大量美元值输入到 Rails 货币对象中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30040239/

相关文章:

ruby-on-rails - 使用 Redis 进行 Rails 验证

ruby-on-rails - Ruby on Rails,如何在登录页面上停止导航栏呈现?

ruby-on-rails - 如何在 I18n 语言环境中放置 CSS 样式?

ruby-on-rails - rspec-given 错误 `Then` 在示例中不可用(例如 `it` block )

postgresql - 可以在 AWS RDS 上启用 "JIT compilation using LLVM"Postgres 11 功能吗?

SQL:如何根据类别进行选择?

ruby - Mongoid 是否可以覆盖 updated_at 时间戳

python - SQL,每1000行添加相同的序号

html - 当 link_to 覆盖我应用的 css 类时该怎么办?

javascript - 如何使用 Rails 4.1 Bootstrap 获取弹出表单以将更多详细信息传递给 Controller