参见英文答案 >
naked asterisk as parameter in method definition: def f(*)1个
当我阅读Rails代码时,我发现了这一点
当我阅读Rails代码时,我发现了这一点
def save(*) create_or_update || raise(RecordNotSaved) end
*做什么? :o
我知道当我们像* args一样使用它时会发生什么,但在这种情况下,它只是简单*.
ref https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L119
解决方法
在这种特定情况下,save不带任何参数.这就是赤裸裸的啪啪声.但是,您可能知道,在ActiveRecord模型上调用save会接受选项,因为此方法会被ActiveRecord :: Validations覆盖:
https://github.com/rails/rails/blob/v3.1.3/activerecord/lib/active_record/validations.rb#L47
# The validation process on save can be skipped by passing <tt>:validate => false</tt>. The regular Base#save method is # replaced with this when the validations module is mixed in,which it is by default. def save(options={}) perform_validations(options) ? super : false end