Class: Munificent::Admin::GamesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/munificent/admin/games_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/munificent/admin/games_controller.rb', line 11

def create
  if @game.save
    flash[:notice] = "Game created"
    redirect_to edit_game_path(@game)
  else
    flash[:alert] = @game.errors.full_messages.join(", ")
    redirect_to new_game_path
  end
end

#csv_uploadObject



38
39
40
# File 'app/controllers/munificent/admin/games_controller.rb', line 38

def csv_upload
  authorize! :manage, Key
end

#destroyObject



33
34
35
36
# File 'app/controllers/munificent/admin/games_controller.rb', line 33

def destroy
  @game.destroy
  redirect_to games_path
end

#editObject



9
# File 'app/controllers/munificent/admin/games_controller.rb', line 9

def edit; end

#indexObject



6
# File 'app/controllers/munificent/admin/games_controller.rb', line 6

def index; end

#newObject



8
# File 'app/controllers/munificent/admin/games_controller.rb', line 8

def new; end

#showObject



7
# File 'app/controllers/munificent/admin/games_controller.rb', line 7

def show; end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/munificent/admin/games_controller.rb', line 21

def update
  @game.assign_attributes(game_params)

  if @game.save
    flash[:notice] = "Game saved"
  else
    flash[:alert] = @game.errors.full_messages.join(", ")
  end

  redirect_to edit_game_path(@game)
end

#upload_csvObject



42
43
44
45
46
47
48
# File 'app/controllers/munificent/admin/games_controller.rb', line 42

def upload_csv
  authorize! :manage, Key
  params.fetch(:csv).tempfile.each_line do |code|
    resource.keys.create(code: code.chomp)
  end
  redirect_to games_path
end