diff options
| -rw-r--r-- | app/controllers/downloads_controller.rb | 69 | ||||
| -rw-r--r-- | app/views/downloads/_form.html.erb | 37 | ||||
| -rw-r--r-- | app/views/downloads/edit.html.erb | 6 | ||||
| -rw-r--r-- | app/views/downloads/new.html.erb | 5 | ||||
| -rw-r--r-- | app/views/downloads/show.html.erb | 29 | ||||
| -rw-r--r-- | app/views/downloads/show.json.jbuilder | 1 | ||||
| -rw-r--r-- | config/routes.rb | 58 | 
7 files changed, 6 insertions, 199 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 diff --git a/app/views/downloads/_form.html.erb b/app/views/downloads/_form.html.erb deleted file mode 100644 index 1ab1879..0000000 --- a/app/views/downloads/_form.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<%= form_for(@download) do |f| %> -  <% if @download.errors.any? %> -    <div id="error_explanation"> -      <h2><%= pluralize(@download.errors.count, "error") %> prohibited this download from being saved:</h2> - -      <ul> -      <% @download.errors.full_messages.each do |message| %> -        <li><%= message %></li> -      <% end %> -      </ul> -    </div> -  <% end %> - -  <div class="field"> -    <%= f.label :name %><br> -    <%= f.text_field :name %> -  </div> -  <div class="field"> -    <%= f.label :filename %><br> -    <%= f.text_field :filename %> -  </div> -  <div class="field"> -    <%= f.label :type %><br> -    <%= f.text_field :type %> -  </div> -  <div class="field"> -    <%= f.label :description %><br> -    <%= f.text_area :description %> -  </div> -  <div class="field"> -    <%= f.label :hits %><br> -    <%= f.number_field :hits %> -  </div> -  <div class="actions"> -    <%= f.submit %> -  </div> -<% end %> diff --git a/app/views/downloads/edit.html.erb b/app/views/downloads/edit.html.erb deleted file mode 100644 index 3b57a65..0000000 --- a/app/views/downloads/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<h1>Editing Download</h1> - -<%= render 'form' %> - -<%= link_to 'Show', @download %> | -<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/new.html.erb b/app/views/downloads/new.html.erb deleted file mode 100644 index ac31df5..0000000 --- a/app/views/downloads/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<h1>New Download</h1> - -<%= render 'form' %> - -<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/show.html.erb b/app/views/downloads/show.html.erb deleted file mode 100644 index 276888a..0000000 --- a/app/views/downloads/show.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<p id="notice"><%= notice %></p> - -<p> -  <strong>Name:</strong> -  <%= @download.name %> -</p> - -<p> -  <strong>Filename:</strong> -  <%= @download.filename %> -</p> - -<p> -  <strong>Type:</strong> -  <%= @download.type %> -</p> - -<p> -  <strong>Description:</strong> -  <%= @download.description %> -</p> - -<p> -  <strong>Hits:</strong> -  <%= @download.hits %> -</p> - -<%= link_to 'Edit', edit_download_path(@download) %> | -<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/show.json.jbuilder b/app/views/downloads/show.json.jbuilder deleted file mode 100644 index 6bab62c..0000000 --- a/app/views/downloads/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @download, :id, :name, :filename, :type, :description, :hits, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 33b0274..6487e82 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,59 +1,3 @@  Rails.application.routes.draw do -  get 'downloads' => 'downloads#index' -  get 'downloads/:filename' => 'downloads#download', :filename => /.+/, :as => 'download' - -  # The priority is based upon order of creation: first created -> highest priority. -  # See how all your routes lay out with "rake routes". - -  # You can have the root of your site routed with "root" -  # root 'welcome#index' - -  # Example of regular route: -  #   get 'products/:id' => 'catalog#view' - -  # Example of named route that can be invoked with purchase_url(id: product.id) -  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - -  # Example resource route (maps HTTP verbs to controller actions automatically): -  #   resources :products - -  # Example resource route with options: -  #   resources :products do -  #     member do -  #       get 'short' -  #       post 'toggle' -  #     end -  # -  #     collection do -  #       get 'sold' -  #     end -  #   end - -  # Example resource route with sub-resources: -  #   resources :products do -  #     resources :comments, :sales -  #     resource :seller -  #   end - -  # Example resource route with more complex sub-resources: -  #   resources :products do -  #     resources :comments -  #     resources :sales do -  #       get 'recent', on: :collection -  #     end -  #   end - -  # Example resource route with concerns: -  #   concern :toggleable do -  #     post 'toggle' -  #   end -  #   resources :posts, concerns: :toggleable -  #   resources :photos, concerns: :toggleable - -  # Example resource route within a namespace: -  #   namespace :admin do -  #     # Directs /admin/products/* to Admin::ProductsController -  #     # (app/controllers/admin/products_controller.rb) -  #     resources :products -  #   end +  resources :downloads, :only => [:index, :show], :id => /.+/  end | 
