Class: Guts::OptionsController

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

Overview

Options controller

Instance Method Summary collapse

Instance Method Details

#createObject

Note:

Redirects to #index if successfull or re-renders #new if not

Creates an option through post



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/guts/options_controller.rb', line 32

def create
  @option = Option.new option_params
  authorize @option

  if @option.save
    flash[:notice] = 'Option was successfully created.'
    redirect_to edit_option_path(@option)
  else
    render :new
  end
end

#destroyObject

Destroys an option



58
59
60
61
62
63
64
# File 'app/controllers/guts/options_controller.rb', line 58

def destroy
  authorize @option
  @option.destroy

  flash[:notice] = 'Option was successfully destroyed.'
  redirect_to options_path
end

#editObject

Editing of an option



26
27
28
# File 'app/controllers/guts/options_controller.rb', line 26

def edit
  authorize @option
end

#indexObject

Display a list of options



10
11
12
# File 'app/controllers/guts/options_controller.rb', line 10

def index
  @options = policy_scope(Option).paginate(page: params[:page], per_page: @per_page)
end

#newObject

Creation of a new option



20
21
22
23
# File 'app/controllers/guts/options_controller.rb', line 20

def new
  @option = Option.new
  authorize @option
end

#showObject

Show a single options



15
16
17
# File 'app/controllers/guts/options_controller.rb', line 15

def show
  authorize @option
end

#updateObject

Note:

Redirects to #index if successfull or re-renders #edit if not

Updates an option through patch



46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/guts/options_controller.rb', line 46

def update
  authorize @option

  if @option.update option_params
    flash[:notice] = 'Option was successfully updated.'
    redirect_to edit_option_path(@option)
  else
    render :edit
  end
end