Class: CardsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/cards_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#not_authenticated, #set_locale

Instance Method Details

#createObject


19
20
21
22
23
24
25
26
27
# File 'app/controllers/cards_controller.rb', line 19

def create
  @deck = new_deck
  @card = @deck.cards.new(card_params)
  if @card.save
    redirect_to decks_path
  else
    render "new"
  end
end

#destroyObject


37
38
39
40
# File 'app/controllers/cards_controller.rb', line 37

def destroy
  @card.destroy
  redirect_to :back
end

#editObject


16
17
# File 'app/controllers/cards_controller.rb', line 16

def edit
end

#indexObject


4
5
6
# File 'app/controllers/cards_controller.rb', line 4

def index
  @cards = current_user.cards
end

#newObject


11
12
13
14
# File 'app/controllers/cards_controller.rb', line 11

def new
  @card = Card.new
  @deck = @card.build_deck
end

#showObject


8
9
# File 'app/controllers/cards_controller.rb', line 8

def show
end

#updateObject


29
30
31
32
33
34
35
# File 'app/controllers/cards_controller.rb', line 29

def update
  if @card.update(card_params) && @card.update_attributes(deck: new_deck)
    redirect_to deck_path(@card.deck)
  else
    render "edit"
  end
end