Class: ResourcesController

Inherits:
ApplicationController show all
Includes:
PermittedParameters
Defined in:
app/controllers/resources_controller.rb

Overview

Handles CRUD actions for Resource objects

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  self.resource = current_organization.resources.new(resource_params)

  if resource.save
    logger.info "Created #{resource}"
    redirect_to resource, notice: 'The resource has been created'
  else
    logger.warn "Unable to create resource due to '#{resource.error_sentence}'"
    render :new
  end
end

#destroyObject



51
52
53
54
# File 'app/controllers/resources_controller.rb', line 51

def destroy
  resource.destroy
  redirect_to organization_resources_url(current_organization), notice: 'Resource was successfully destroyed.'
end

#editObject



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

def edit
end

#indexObject



13
14
# File 'app/controllers/resources_controller.rb', line 13

def index
end

#newObject



19
20
21
22
23
24
# File 'app/controllers/resources_controller.rb', line 19

def new
  self.resource = current_organization.resources.new(
    title: '',
    resource_group: current_organization.resource_groups.default.first
  )
end

#showObject



16
17
# File 'app/controllers/resources_controller.rb', line 16

def show
end

#updateObject



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

def update
  if resource.update(resource_params)
    logger.info "Updated #{resource}"
    redirect_to resource, notice: 'The resource has been updated'
  else
    logger.warn "Unable to update resource due to '#{resource.error_sentence}'"
    render :edit
  end
end