diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2015-03-29 14:23:06 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2015-03-29 14:23:06 -0700 |
commit | 771a881c910a8fb0c9dbface321bd39582b9c1bb (patch) | |
tree | 1d35359c71b812671e3ea734e16d64c7dfcc68f7 /app/controllers | |
parent | 1370d21460255914e03754fb0f20052e6b3002d7 (diff) |
Cleaning up routes and the Downloads controller.
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/downloads_controller.rb | 69 |
1 files changed, 5 insertions, 64 deletions
diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb index 2681b0a..14e3b04 100644 --- a/app/controllers/downloads_controller.rb +++ b/app/controllers/downloads_controller.rb @@ -11,16 +11,16 @@ class DownloadsController < ApplicationController end # GET /downloads/:filename - def download - download = Download.find_by(filename: params[:filename]) or not_found + def show + not_found if @download.nil? s3client = Aws::S3::Client.new() - s3obj = Aws::S3::Object.new(ENV['S3_DOWNLOADS_BUCKET'], download.filename, client: s3client) + s3obj = Aws::S3::Object.new(ENV['S3_DOWNLOADS_BUCKET'], @download.filename, client: s3client) resp = s3obj.get FileUtils.mkdir_p(Rails.root.join('tmp', 'downloads')) - cached_filename = Rails.root.join('tmp', 'downloads', download.filename) + cached_filename = Rails.root.join('tmp', 'downloads', @download.filename) File.open(cached_filename, 'wb') do |file| file.write resp.body.read @@ -29,68 +29,9 @@ class DownloadsController < ApplicationController send_file cached_filename end - # GET /downloads/1 - # GET /downloads/1.json - def show - end - - # GET /downloads/new - def new - @download = Download.new - end - - # GET /downloads/1/edit - def edit - end - - # POST /downloads - # POST /downloads.json - def create - @download = Download.new(download_params) - - respond_to do |format| - if @download.save - format.html { redirect_to @download, notice: 'Download was successfully created.' } - format.json { render :show, status: :created, location: @download } - else - format.html { render :new } - format.json { render json: @download.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /downloads/1 - # PATCH/PUT /downloads/1.json - def update - respond_to do |format| - if @download.update(download_params) - format.html { redirect_to @download, notice: 'Download was successfully updated.' } - format.json { render :show, status: :ok, location: @download } - else - format.html { render :edit } - format.json { render json: @download.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /downloads/1 - # DELETE /downloads/1.json - 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 - private # Use callbacks to share common setup or constraints between actions. def set_download - @download = Download.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def download_params - params.require(:download).permit(:name, :filename, :type, :description, :hits) + @download = Download.find_by(filename: params[:id]) end end |