Class: Guts::MediaController

Inherits:
ApplicationController show all
Includes:
ControllerPermissionConcern
Defined in:
app/controllers/guts/media_controller.rb

Overview

Media controller

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Methods included from MultisiteConcern

#current_site, #with_current_site

Instance Method Details

#createObject

Note:

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

Creates a medium through post



38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/guts/media_controller.rb', line 38

def create
  @medium = Medium.new medium_params

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

#destroyObject

Note:

Redirects to #index on success

Destroys a medium



62
63
64
65
66
67
# File 'app/controllers/guts/media_controller.rb', line 62

def destroy
  @medium.destroy

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

#editObject

Editing for a medium



33
34
# File 'app/controllers/guts/media_controller.rb', line 33

def edit
end

#editor_insertObject

Handles showing the insert medium allowing TinyMce to use it



71
72
73
# File 'app/controllers/guts/media_controller.rb', line 71

def editor_insert
  render :editor_insert, layout: false
end

#indexObject

Note:

Depending on the object passed (polymorphic)

Displays a list of media



15
16
17
18
19
20
21
# File 'app/controllers/guts/media_controller.rb', line 15

def index
  @media = if @object
             @object.media.paginate(page: params[:page], per_page: @per_page)
           else
             Medium.paginate(page: params[:page], per_page: @per_page)
           end
end

#newObject

Creation of a new medium



28
29
30
# File 'app/controllers/guts/media_controller.rb', line 28

def new
  @medium = Medium.new
end

#showObject

Shows details about a single medium



24
25
# File 'app/controllers/guts/media_controller.rb', line 24

def show
end

#updateObject

Note:

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

Updates a medium through patch



51
52
53
54
55
56
57
58
# File 'app/controllers/guts/media_controller.rb', line 51

def update
  if @medium.update(medium_params)
    flash[:notice] = 'Media was successfully updated.'
    redirect_to edit_polymorphic_path([@object, @medium])
  else
    render :edit
  end
end