Class: Renalware::System::DownloadsController

Inherits:
BaseController show all
Includes:
Concerns::Pageable
Defined in:
app/controllers/renalware/system/downloads_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/renalware/system/downloads_controller.rb', line 21

def create
  download = Download.new(download_params)
  authorize download
  if download.save_by(current_user)
    redirect_to system_downloads_path, notice: notice
  else
    render_new(download)
  end
end

#destroyObject



44
45
46
47
48
# File 'app/controllers/renalware/system/downloads_controller.rb', line 44

def destroy
  download = find_and_authorize_download
  download.destroy!
  redirect_to system_downloads_path, notice: notice
end

#editObject



31
32
33
# File 'app/controllers/renalware/system/downloads_controller.rb', line 31

def edit
  render_edit(find_and_authorize_download)
end

#indexObject



8
9
10
11
12
13
# File 'app/controllers/renalware/system/downloads_controller.rb', line 8

def index
  query = DownloadQuery.new(params[:q])
  items = query.call.page(page).per(per_page)
  authorize items
  render locals: { items: items, search: query.search }
end

#newObject



15
16
17
18
19
# File 'app/controllers/renalware/system/downloads_controller.rb', line 15

def new
  download = Download.new
  authorize download
  render_new(download)
end

#showObject

Redirects the uploaded file eg PDF etc



51
52
53
54
55
56
57
# File 'app/controllers/renalware/system/downloads_controller.rb', line 51

def show
  download = find_and_authorize_download
  if download.file.attached?
    update_view_count_for download
    redirect_to(raw_active_storage_url_for(download.file))
  end
end

#updateObject



35
36
37
38
39
40
41
42
# File 'app/controllers/renalware/system/downloads_controller.rb', line 35

def update
  download = find_and_authorize_download
  if download.update_by(current_user, download_params)
    redirect_to system_downloads_path, notice: notice
  else
    render_edit(download)
  end
end