Class: Guts::ContentsController

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

Overview

Contents 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 content through post



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/guts/contents_controller.rb', line 34

def create
  @content      = Content.new content_params
  @content.user = current_user
  @content.type = @type

  if @content.save
    flash[:notice] = "#{@content.type.title} was successfully created."
    redirect_to edit_content_path(@content)
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a content



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

def destroy
  @content.destroy

  flash[:notice] = "#{@content.type.title} was successfully destroyed."
  redirect_to contents_path(type: @content.type.slug)
end

#editObject

Editting of a content



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

def edit
end

#indexObject

Note:

This method must have a type set

Displays a list of contents



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

def index
  @contents = Content.where(type: @type).paginate(page: params[:page], per_page: @per_page)
end

#newObject

Creation of a content



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

def new
  @content = Content.new
end

#showObject

Shows details about a single content



25
26
# File 'app/controllers/guts/contents_controller.rb', line 25

def show
end

#updateObject

Note:

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

Updates a content through patch



49
50
51
52
53
54
55
56
# File 'app/controllers/guts/contents_controller.rb', line 49

def update
  if @content.update(content_params)
    flash[:notice] = "#{@content.type.title} was successfully updated."
    redirect_to edit_content_path(@content)
  else
    render :edit
  end
end