我有一个:before_create
方法可以执行一些检查并返回false
or true
。
def create_subscription_on_gateway
gateway = self.keyword.shortcode.provider
create_subscription = gateway.classify.constantize.new.create_subscription(self.phone,self.keyword_keyword,self.shortcode_shortcode,self.country)
errors[:base] << "An error has occurred when finding gateway." if gateway.nil?
errors[:base] << "No gateway found for this shortcode." if create_subscription.nil?
errors[:base] << "Subscription could not be made." if create_subscription == false
end
现在,如果方法返回false
,或者nil
我可以在表单页面上看到错误,那没关系。问题是对象已保存到数据库中。
当对象上仍然存在相关错误时,如何防止对象被保存?