【问题标题】:What is the exclamation mark in Spree::Product.create(exclamation mark) method?Spree::Product.create(exclamation mark) 方法中的感叹号是什么?
【发布时间】:2018-01-18 10:45:53
【问题描述】:

我在使用 Spree 时遇到了一些问题,看到 this code,其中提到了 Spree::Product.create!(而不是 Spree::Product.create 没有 !

我想了解这两种方法的区别。

【问题讨论】:

    标签: ruby-on-rails spree


    【解决方案1】:

    如果记录无效,爆炸版本(例如 Spree::Product.create!)会引发异常。非爆炸版本不会:Spree::Product.create 返回 false。

    参考:http://edgeguides.rubyonrails.org/active_record_validations.html#when-does-validation-happen-questionmark

    【讨论】:

    • 谢谢。这就说得通了。那么该方法是继承自 Active Record 的呢?
    猜你喜欢
    • 2011-12-22
    • 2018-11-14
    • 1970-01-01
    • 2020-05-03
    • 2010-10-11
    • 2011-01-11
    • 1970-01-01
    • 2023-03-06
    • 2015-09-01
    相关资源
    最近更新 更多