Class: DecksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/decks_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
# File 'app/controllers/decks_controller.rb', line 19

def create
  @deck = current_user.decks.new(deck_params)
  if @deck.save
    redirect_to decks_path
  else
    render "new"
  end
end

#destroyObject


36
37
38
39
# File 'app/controllers/decks_controller.rb', line 36

def destroy
  @deck.destroy
  redirect_to decks_path
end

#editObject


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

def edit
end

#indexObject


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

def index
  @decks = current_user.decks
end

#newObject


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

def new
  @deck = Deck.new
end

#set_defaultObject


41
42
43
44
# File 'app/controllers/decks_controller.rb', line 41

def set_default
  current_user.update_attributes(default_deck_id: params[:id])
  redirect_to profile_path
end

#showObject


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

def show
  @cards = @deck.cards
end

#updateObject


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

def update
  if @deck.update(deck_params)
    redirect_to decks_path
  else
    render "edit"
  end
end