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

#csrf_token, #initialize, #log_activity, #params, #redirect_to, #render, #render_json, #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
24
# 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
    log_activity("Created project: #{@project.title}", @project, "Link: #{@project.link}")
    redirect_to '/dashboard/projects'
  else
    render 'cms/projects_form'
  end
end

#destroyObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/projects_controller.rb', line 43

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)
  title = @project.title
  @project.destroy
  log_activity("Deleted project: #{title}")
  redirect_to '/dashboard/projects'
end

#editObject



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

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



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

def update
  @project = Project[params['id']]
  data = params['project']
  data['is_active'] = boolean_param(data['is_active'])
  if @project.update(data)
    log_activity("Updated project: #{@project.title}", @project, "New Data: #{data.to_json}")
    redirect_to '/dashboard/projects'
  else
    render 'cms/projects_form'
  end
end