Class: ProjectsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#req, #res

Instance Method Summary collapse

Methods inherited from ApplicationController

#boolean_param, #csrf_token, #delete_all_images_from_content, #delete_from_storage, #initialize, #params, #redirect_to, #render, #session, #validate!

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/projects_controller.rb', line 14

def create
  data = params['project']
  data['is_active'] = boolean_param(data['is_active'])
  @project = Project.new(data)
  if @project.save
    redirect_to '/dashboard/projects'
  else
    render 'cms/projects_form'
  end
end

#destroyObject



41
42
43
44
45
46
47
# File 'app/controllers/projects_controller.rb', line 41

def destroy
  @project = Project[params['id']]
  delete_from_storage(@project.image_url) if @project.respond_to?(:image_url)
  delete_all_images_from_content(@project.description) if @project.respond_to?(:description)
  @project.destroy
  redirect_to '/dashboard/projects'
end

#editObject



25
26
27
28
# File 'app/controllers/projects_controller.rb', line 25

def edit
  @project = Project[params['id']]
  render 'cms/projects_form'
end

#indexObject



4
5
6
7
# File 'app/controllers/projects_controller.rb', line 4

def index
  @projects = Project.order(Sequel.desc(:created_at)).all
  render 'cms/projects_index'
end

#newObject



9
10
11
12
# File 'app/controllers/projects_controller.rb', line 9

def new
  @project = Project.new
  render 'cms/projects_form'
end

#updateObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/projects_controller.rb', line 30

def update
  @project = Project[params['id']]
  data = params['project']
  data['is_active'] = boolean_param(data['is_active'])
  if @project.update(data)
    redirect_to '/dashboard/projects'
  else
    render 'cms/projects_form'
  end
end