:before_create
いくつかのチェックとリターンfalse
またはを実行するメソッドがあります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
、フォームページにエラーが表示されれば問題ありません。問題は、オブジェクトがデータベースに保存されていることです。
エラーがまだ関連付けられているときにオブジェクトが保存されないようにするにはどうすればよいですか?