Class: Railspress::Admin::ContentGroupsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/railspress/admin/content_groups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 24

def create
  @content_group = ContentGroup.new(content_group_params)
  @content_group.author_id = current_author&.id if authors_enabled?

  if @content_group.save
    redirect_to admin_content_group_path(@content_group), notice: "Content group '#{@content_group.name}' created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 46

def destroy
  if @content_group.soft_delete
    redirect_to admin_content_groups_path,
      notice: "Content group '#{@content_group.name}' deleted."
  else
    redirect_to admin_content_group_path(@content_group),
      alert: "Cannot delete '#{@content_group.name}' — it contains required content elements."
  end
end

#editObject



35
36
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 35

def edit
end

#indexObject



8
9
10
11
12
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 8

def index
  @content_groups = ContentGroup.active
                                .includes(:content_elements)
                                .order(created_at: :desc)
end

#newObject



20
21
22
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 20

def new
  @content_group = ContentGroup.new
end

#showObject



14
15
16
17
18
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 14

def show
  @content_elements = @content_group.content_elements
                                    .active
                                    .ordered
end

#updateObject



38
39
40
41
42
43
44
# File 'app/controllers/railspress/admin/content_groups_controller.rb', line 38

def update
  if @content_group.update(content_group_params)
    redirect_to admin_content_group_path(@content_group), notice: "Content group '#{@content_group.name}' updated."
  else
    render :edit, status: :unprocessable_entity
  end
end