diff --git a/Gemfile b/Gemfile index 9d1fcfa..7f0eec6 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ gem 'jbuilder', '~> 2.7' gem 'bootstrap', '~> 4.3.1' gem 'jquery-rails' gem 'image_processing' +gem 'active_storage-send_zip' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 493c989..266e132 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,9 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_storage-send_zip (0.3.3) + rails (> 5.2) + rubyzip (< 3.0) activejob (6.0.3.1) activesupport (= 6.0.3.1) globalid (>= 0.3.6) @@ -210,6 +213,7 @@ PLATFORMS ruby DEPENDENCIES + active_storage-send_zip bootsnap (>= 1.4.2) bootstrap (~> 4.3.1) byebug diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index eeb2187..4999e23 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -20,17 +20,19 @@ def edit # POST /images # POST /images.json def create - @image = Image.new(create_params) + parameters =create_params + parameters[:files].each do |f| + tmp = {:title => parameters[:title], :private => parameters[:private], :tags => parameters[:tags], :file => f} - respond_to do |format| - if @image.save - format.html { redirect_to root_path, notice: 'Image was successfully created.' } - format.json { render :show, status: :created, location: @image } - else + @image = Image.create!(tmp) + if !(@image.save) format.html { render :new } format.json { render json: @image.errors, status: :unprocessable_entity } end + + end + redirect_to root_path, notice: 'Image was successfully created.' end # PATCH/PUT /images/1 @@ -50,13 +52,33 @@ def update # DELETE /images/1 # DELETE /images/1.json def destroy + @image.file.purge @image.destroy respond_to do |format| - format.html { redirect_to images_url, notice: 'Image was successfully destroyed.' } + format.html { redirect_to root_path, notice: 'Image was successfully destroyed.' } format.json { head :no_content } end end + def destroy_all + @image.file.purge + @image.destroy + respond_to do |format| + format.html { redirect_to root_path, notice: 'Image was successfully destroyed.' } + format.json { head :no_content } + end + end + + + def download + send_data @resume, type: "application/pdf", disposition: "attachment" + end + + def download_all + send_data @resume, type: "application/pdf", disposition: "attachment" + end + + private # Use callbacks to share common setup or constraints between actions. def set_image @@ -65,16 +87,14 @@ def set_image # Only allow a list of trusted parameters through. def create_params - params.require(:title) - params.require(:file) + params.require(:files) + # byebug params.require(:private) - params.permit(:title, :tags, :file, :private) + params.permit(:title, :tags, :private, files: []) end # Only allow a list of trusted parameters through. def update_params - params.require(:title) - params.require(:private) params.permit(:title, :tags, :private) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb deleted file mode 100644 index 3485a4d..0000000 --- a/app/controllers/users_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -class UsersController < ApplicationController - before_action :set_user, only: [:show, :edit, :update, :destroy] - - # GET /users - # GET /users.json - def index - @users = User.all - end - - # GET /users/1 - # GET /users/1.json - def show - end - - # GET /users/new - def new - @user = User.new - end - - # GET /users/1/edit - def edit - end - - # POST /users - # POST /users.json - def create - @user = User.new(user_params) - - respond_to do |format| - if @user.save - format.html { redirect_to @user, notice: 'User was successfully created.' } - format.json { render :show, status: :created, location: @user } - else - format.html { render :new } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /users/1 - # PATCH/PUT /users/1.json - def update - respond_to do |format| - if @user.update(user_params) - format.html { redirect_to @user, notice: 'User was successfully updated.' } - format.json { render :show, status: :ok, location: @user } - else - format.html { render :edit } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /users/1 - # DELETE /users/1.json - def destroy - @user.destroy - respond_to do |format| - format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_user - @user = User.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def user_params - params.fetch(:user, {}) - end -end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb deleted file mode 100644 index 2310a24..0000000 --- a/app/helpers/users_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module UsersHelper -end diff --git a/app/views/images/edit.html.erb b/app/views/images/edit.html.erb index 62eeadd..9ee2fab 100644 --- a/app/views/images/edit.html.erb +++ b/app/views/images/edit.html.erb @@ -1,25 +1,22 @@
<%= notice %>
- -- | ||
---|---|---|
<%= link_to 'Show', image %> | -<%= link_to 'Edit', edit_image_path(image) %> | -<%= link_to 'Destroy', image, method: :delete, data: { confirm: 'Are you sure?' } %> | -
<%= img.title %>
+ + <% if img.tags %> +Tags: <%= img.tags %>
+ <% end %> + + <%= link_to "View", image_path(img), :class => "btn btn-light" %> + +Tags: <%= @image.tags %>
<% end %> - <%= link_to 'Edit', edit_image_path(@image) , :class => "btn btn-light"%> - <%= link_to 'Back', images_path , :class => "btn btn-light"%> + <%= link_to 'Edit', edit_image_path(@image), :class => "btn btn-light"%> + <%= link_to "Download", download_image_path(@image), "data-turbolinks" => false, :class => "btn btn-light" %> + + <%= link_to 'Back', root_path , :class => "btn btn-light"%> diff --git a/app/views/site/upload.html.erb b/app/views/images/upload.html.erb similarity index 79% rename from app/views/site/upload.html.erb rename to app/views/images/upload.html.erb index 3389ae3..23caae5 100644 --- a/app/views/site/upload.html.erb +++ b/app/views/images/upload.html.erb @@ -2,12 +2,12 @@ <%= form_with(url: images_create_path, method: "post", :html => {:class => "form-horizontal center"}) do |form| %><%= img.title %>
- - <% if img.tags %> -Tags: <%= img.tags %>
- <% end %> - -<%= img.title %>
- - <% if img.tags %> -Tags: <%= img.tags %>
- <% end %> - -<%= notice %>
- -- | ||
---|---|---|
<%= link_to 'Show', user %> | -<%= link_to 'Edit', edit_user_path(user) %> | -<%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %> | -
<%= notice %>
- -<%= link_to 'Edit', edit_user_path(@user) %> | -<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder deleted file mode 100644 index ff40bb9..0000000 --- a/app/views/users/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "users/user", user: @user diff --git a/config/routes.rb b/config/routes.rb index 90e7014..050aa5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,12 @@ Rails.application.routes.draw do - get 'site/home' get 'site/upload' - get 'site/private' + get 'images/upload' post 'images/create' - - root to: 'site#home' - resources :users - resources :images - # get 'site/home' + root to: 'images#index' + resources :images do + get :download, on: :member + end # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb deleted file mode 100644 index 2d142e6..0000000 --- a/test/controllers/users_controller_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'test_helper' - -class UsersControllerTest < ActionDispatch::IntegrationTest - setup do - @user = users(:one) - end - - test "should get index" do - get users_url - assert_response :success - end - - test "should get new" do - get new_user_url - assert_response :success - end - - test "should create user" do - assert_difference('User.count') do - post users_url, params: { user: { } } - end - - assert_redirected_to user_url(User.last) - end - - test "should show user" do - get user_url(@user) - assert_response :success - end - - test "should get edit" do - get edit_user_url(@user) - assert_response :success - end - - test "should update user" do - patch user_url(@user), params: { user: { } } - assert_redirected_to user_url(@user) - end - - test "should destroy user" do - assert_difference('User.count', -1) do - delete user_url(@user) - end - - assert_redirected_to users_url - end -end diff --git a/test/system/users_test.rb b/test/system/users_test.rb deleted file mode 100644 index 9782a5c..0000000 --- a/test/system/users_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "application_system_test_case" - -class UsersTest < ApplicationSystemTestCase - setup do - @user = users(:one) - end - - test "visiting the index" do - visit users_url - assert_selector "h1", text: "Users" - end - - test "creating a User" do - visit users_url - click_on "New User" - - click_on "Create User" - - assert_text "User was successfully created" - click_on "Back" - end - - test "updating a User" do - visit users_url - click_on "Edit", match: :first - - click_on "Update User" - - assert_text "User was successfully updated" - click_on "Back" - end - - test "destroying a User" do - visit users_url - page.accept_confirm do - click_on "Destroy", match: :first - end - - assert_text "User was successfully destroyed" - end -end