Class: DownloadsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DownloadsController
- Defined in:
- app/controllers/downloads_controller.rb
Instance Method Summary collapse
- #api_file ⇒ Object
- #api_index ⇒ Object
- #api_show ⇒ Object
-
#destroy ⇒ Object
DELETE /downloads/1 DELETE /downloads/1.json.
- #download_params ⇒ Object private
-
#file ⇒ Object
GET /downloads/1/file.
-
#index ⇒ Object
GET /downloads GET /downloads.json.
-
#list ⇒ Object
GET /downloads/list GET /downloads/list.json.
- #set_download ⇒ Object private
- #set_download_api ⇒ Object private
-
#show ⇒ Object
GET /downloads/1.
-
#update ⇒ Object
PATCH /downloads/1 PATCH /downloads/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_file ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/controllers/downloads_controller.rb', line 59 def api_file if @download.ready? @download.increment!(:times_downloaded) send_file @download.file_path else render json: { success: false } end end |
#api_index ⇒ Object
53 54 55 56 57 |
# File 'app/controllers/downloads_controller.rb', line 53 def api_index @downloads = Download.where(is_public: true, project_id: sessions_current_project_id) .order('downloads.id').page(params[:page]).per(params[:per]) render '/downloads/api/v1/index' end |
#api_show ⇒ Object
68 69 70 |
# File 'app/controllers/downloads_controller.rb', line 68 def api_show render '/downloads/api/v1/show' end |
#destroy ⇒ Object
DELETE /downloads/1 DELETE /downloads/1.json
22 23 24 25 26 27 28 |
# File 'app/controllers/downloads_controller.rb', line 22 def destroy @download.destroy respond_to do |format| format.html { redirect_to downloads_url, notice: 'Download was successfully destroyed.' } format.json { head :no_content } end end |
#download_params ⇒ Object (private)
82 83 84 |
# File 'app/controllers/downloads_controller.rb', line 82 def download_params params.require(:download).permit(:is_public) end |
#file ⇒ Object
GET /downloads/1/file
44 45 46 47 48 49 50 51 |
# File 'app/controllers/downloads_controller.rb', line 44 def file if @download.ready? @download.increment!(:times_downloaded) send_file @download.file_path else redirect_to download_url end end |
#index ⇒ Object
GET /downloads GET /downloads.json
11 12 13 14 |
# File 'app/controllers/downloads_controller.rb', line 11 def index @recent_objects = Download.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' end |
#list ⇒ Object
GET /downloads/list GET /downloads/list.json
39 40 41 |
# File 'app/controllers/downloads_controller.rb', line 39 def list @downloads = Download.where(project_id: sessions_current_project_id).order(:id).page(params[:page]).per(params[:per]) end |
#set_download ⇒ Object (private)
74 75 76 |
# File 'app/controllers/downloads_controller.rb', line 74 def set_download @download = Download.unscoped.where(project_id: sessions_current_project_id).find(params[:id]) end |
#set_download_api ⇒ Object (private)
78 79 80 |
# File 'app/controllers/downloads_controller.rb', line 78 def set_download_api @download = Download.unscoped.where(is_public: true, project_id: sessions_current_project_id).find(params[:id]) end |
#show ⇒ Object
GET /downloads/1
17 18 |
# File 'app/controllers/downloads_controller.rb', line 17 def show end |
#update ⇒ Object
PATCH /downloads/1 PATCH /downloads/1.json
32 33 34 35 |
# File 'app/controllers/downloads_controller.rb', line 32 def update @download.update(download_params) render action: :show end |