Class: Guts::ContentsController

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

Overview

Contents controller

Instance Method Summary collapse

Methods included from SessionsHelper

#current_user, #log_in, #log_out, #logged_in?

Instance Method Details

#createObject

Note:

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

Creates a content through post



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

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

  if @content.save
    redirect_to contents_path(type: @content.type.slug), notice: "#{@content.type.title} was successfully created."
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a category



54
55
56
57
# File 'app/controllers/guts/contents_controller.rb', line 54

def destroy
  @content.destroy
  redirect_to contents_path(type: @content.type.slug), notice: "#{@content.type.title} was successfully destroyed."
end

#editObject

Editting of a content



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

def edit
end

#indexObject

Note:

This method must have a type set

Displays a list of contents



12
13
14
# File 'app/controllers/guts/contents_controller.rb', line 12

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

#newObject

Creation of a content



17
18
19
# File 'app/controllers/guts/contents_controller.rb', line 17

def new
  @content = Content.new
end

#showObject

Shows details about a single content



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

def show
end

#updateObject

Note:

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

Updates a content through patch



44
45
46
47
48
49
50
# File 'app/controllers/guts/contents_controller.rb', line 44

def update
  if @content.update(content_params)
    redirect_to contents_path(type: @content.type.slug), notice: "#{@content.type.title} was successfully updated."
  else
    render :edit
  end
end