Class: Guts::MetafieldsController

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

Overview

Metafields controller

Instance Method Summary collapse

Instance Method Details

#createObject

Note:

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

Creates a metafield through post



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/guts/metafields_controller.rb', line 22

def create
  @metafield = Metafield.new metafield_params
  authorize @metafield

  if @metafield.save
    flash[:notice] = 'Metafield was successfully created.'
    redirect_to edit_polymorphic_path([@object, @metafield])
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a single metafield



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

def destroy
  authorize @metafield
  @metafield.destroy

  flash[:notice] = 'Metafield was successfully destroyed.'
  redirect_to polymorphic_path([@object, :metafields])
end

#editObject

Editing of a metafield



40
41
42
# File 'app/controllers/guts/metafields_controller.rb', line 40

def edit
  authorize @metafield
end

#indexObject

Displays a list of metafields



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

def index
  @metafields = policy_scope(@object).metafields
end

#newObject

Creation of a new metafield



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

def new
  @metafield = Metafield.new
  authorize @metafield
end

#showObject

Shows details about a single metafield



35
36
37
# File 'app/controllers/guts/metafields_controller.rb', line 35

def show
  authorize @metafield
end

#updateObject

Note:

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

Updates a metafields through patch



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

def update
  authorize @metafield

  if @metafield.update metafield_params
    flash[:notice] = 'Metafield was successfully updated.'
    redirect_to edit_polymorphic_path([@object, @metafield])
  else
    render :edit
  end
end