新手问题 Rails 中使用 Gem default_value_for 的问题

mz2test · September 03, 2017 · Last by jasl replied at September 03, 2017 · 1364 hits

Gemfile 中引用

gem 'default_value_for'

在 model 中引用

class Product < ApplicationRecord
  default_value_for :cost_count, 0
end

然后在 console 中执行 new 的时候报错:

Running via Spring preloader in process 759
Loading development environment (Rails 5.1.3)
2.3.4 :001 > Product.new
ArgumentError: wrong number of arguments (given 2, expected 0..1)
    from (irb):1

想问一下这个问题是什么问题?

如果你确定没魔改模型的构造方法,那查这 gem 文档确认是不是用对了

mz2test closed this topic. 14 Sep 09:11
You need to Sign in before reply, if you don't have an account, please Sign up first.