jeudi 19 avril 2018

Rails skip validation within model with save?

I have Rails code like :

1 def charge_card
2            return charge_on_house if house_account?
3            assign_order_number
4           if credit_card?
5              begin
6                save!   #==>here
7                charge = Stripe::Charge.create(
8                  amount: (total.to_f * 100).ceil,
9                  currency: 'usd',
10                  customer: customer.stripe_id,
11                  card: payment_method,
12                 description:"Saint Germain Order: #{self.number}"
13                  )
14                self.update(
15                  payment_status: 'paid'
16                  )
17                self.finish!
18              rescue Stripe::StripeError => e
19                self.update(
20                  admin_comments: e.message,
21                  )
22                self.decline!
23              ensure
24                notify_user
25              end
26            end
27            self.save!
28          end

I want to skip validation on save! on line no 6 rather it is raising the error messages.

Aucun commentaire:

Enregistrer un commentaire