Skip to content
This repository was archived by the owner on Jun 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/download_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class DownloadController < ApplicationController
def file
@file = Upload.find(params[:id])
send_data(@file.data, filename: @file.filename, type: @file.content_type)
end
end
6 changes: 4 additions & 2 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class WelcomeController < ApplicationController
# def index
# end
def index
@files = Upload.order(:created_at).page params[:page]
@upload = Upload.new
end
end
5 changes: 5 additions & 0 deletions app/views/welcome/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
= render 'uploads/form', upload: @upload

%ul
%li Top Rate
%li Today

- @files.each do |file|
= link_to file.filename, download_path(file.id)
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PecaUploader::Application.routes.draw do
get "/download/:id" => 'download#file', as: :download
root "welcome#index"
resources :uploads, only: [:new, :create, :destroy]
end
12 changes: 12 additions & 0 deletions spec/controllers/download_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

describe DownloadController do
let(:file) { FactoryGirl.create :upload }

describe "GET 'file'" do
it "returns http success" do
get :file, id: file.id
response.should be_success
end
end
end