Class: Lcms::Engine::ResourcesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lcms/engine/resources_controller.rb

Instance Method Summary collapse

Instance Method Details

#genericObject



35
36
37
38
39
40
# File 'app/controllers/lcms/engine/resources_controller.rb', line 35

def generic
  resource = Resource.find(params[:id])
  return redirect_to lcms_engine.resource_path(resource) unless resource.generic?

  @resource = GenericPresenter.new(resource)
end

#mediaObject



28
29
30
31
32
33
# File 'app/controllers/lcms/engine/resources_controller.rb', line 28

def media
  resource = Resource.find(params[:id])
  return redirect_to lcms_engine.resource_path(resource) unless resource.media?

  @resource = MediaPresenter.new(resource)
end

#pdf_proxyObject



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

def pdf_proxy
  return head(:not_found) if (url = params[:url]).blank?

  uri = URI.parse(Addressable::URI.escape url)
  send_data uri.open.read, disposition: :inline, file_name: url.split('/').last
rescue StandardError => e
  Rails.logger.warn "PDF-proxy failed! Url: #{url}, Error: #{e.message}"
  head :bad_request
end


22
23
24
25
26
# File 'app/controllers/lcms/engine/resources_controller.rb', line 22

def related_instruction
  @resource = Resource.find params[:id]
  @related_instructions = related_instructions
  render json: { instructions: @instructions }
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/lcms/engine/resources_controller.rb', line 6

def show
  @resource = find_resource

  # redirect to document if resource has it (#161)
  return redirect_to dynamic_document_path(@resource.document) if @resource.document?

  # redirect grade and module to explore_curriculum (#122)
  return redirect_to lcms_engine.explore_curriculum_index_path(p: @resource.slug, e: 1) if grade_or_module?

  # redirect to the path with slug if we are using just the id
  return redirect_to lcms_engine.show_with_slug_path(@resource.slug), status: 301 if using_id?

  @related_instructions = related_instructions
  @props = CurriculumMap.new(@resource).props
end