Class: Gemgento::User::SavedCreditCardsController

Inherits:
BaseController show all
Defined in:
app/controllers/gemgento/user/saved_credit_cards_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/gemgento/user/saved_credit_cards_controller.rb', line 13

def create
  @saved_credit_card = SavedCreditCard.new(saved_credit_card_params)
  @saved_credit_card.user = current_user

  respond_to do |format|
    if @saved_credit_card.save
      format.html { redirect_to user_saved_credit_cards_path, notice: 'Saved credit card successfully created.' }
      format.json { render json: { result: true } }
    else
      format.html { render 'new' }
      format.json { render json: { result: false, errors: @saved_credit_card.errors.full_messages }, status: 422 }
    end
  end
end

#destroyObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/gemgento/user/saved_credit_cards_controller.rb', line 28

def destroy
  @saved_credit_card = SavedCreditCard.find_by(user: current_user, id: params[:id])

  respond_to do |format|
    if @saved_credit_card.destroy
      format.html { redirect_to user_saved_credit_cards_path, notice: 'Saved credit card successfully destroyed.' }
      format.json { render json: { result: true } }
    else
      format.html { redirect_to user_saved_credit_cards_path, alert: 'Saved credit card could not be destroyed.' }
      format.json { render json: { result: false, errors: @saved_credit_card.errors.full_messages }, status: 422 }
    end
  end
end

#indexObject



4
5
6
# File 'app/controllers/gemgento/user/saved_credit_cards_controller.rb', line 4

def index
  @saved_credit_cards = current_user.saved_credit_cards
end

#newObject



8
9
10
11
# File 'app/controllers/gemgento/user/saved_credit_cards_controller.rb', line 8

def new
  @saved_credit_card = SavedCreditCard.new(user: current_user)
  @saved_credit_card.build_address(country: Gemgento::Country.find_by(iso2_code: 'us'))
end