diff --git a/Gemfile b/Gemfile index 8e22019..9246d1a 100644 --- a/Gemfile +++ b/Gemfile @@ -94,3 +94,6 @@ gem 'pg_search' # Use SLIM as our templating language gem 'slim-rails' + +# Attachment/image handling +gem "paperclip", "~> 4.2" diff --git a/Gemfile.lock b/Gemfile.lock index 408b7c7..c056c89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,6 +48,10 @@ GEM columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.5) + climate_control (>= 0.0.3, < 1.0) coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) @@ -93,6 +97,11 @@ GEM multi_json (1.10.1) nokogiri (1.6.5) mini_portile (~> 0.6.0) + paperclip (4.2.1) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + cocaine (~> 0.5.3) + mime-types pg (0.17.1) pg_search (0.7.8) activerecord (>= 3.1) @@ -189,6 +198,7 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-rails jquery.fileupload-rails + paperclip (~> 4.2) pg pg_search rails (= 4.2.0) diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb index 5a51727..985e83d 100644 --- a/app/models/screenshot.rb +++ b/app/models/screenshot.rb @@ -5,6 +5,12 @@ class Screenshot < ActiveRecord::Base order('uploaddatetime DESC') } + has_attached_file :image, + styles: { :large => "800x600>", :thumb => "160x120>" }, + default_url: "/images/dummy/no-screenshots-upload-one.svg" + #path: :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename + validates_attachment_content_type :image, :content_type => /\Aimage\/png\Z/ + def image_url(size) "#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png" end diff --git a/db/schema.rb b/db/schema.rb index cf2c660..489ff6c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141229173351) do +ActiveRecord::Schema.define(version: 20150103194230) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,16 +41,21 @@ ActiveRecord::Schema.define(version: 20141229173351) do create_table "screenshots", force: :cascade do |t| t.integer "package_id" - t.string "version", limit: 50 + t.string "version", limit: 50 t.datetime "uploaddatetime" - t.string "uploaderhash", limit: 72 - t.string "uploaderip", limit: 15 + t.string "uploaderhash", limit: 72 + t.string "uploaderip", limit: 15 t.boolean "approved" t.boolean "markedfordelete" - t.string "delete_reason", limit: 100 - t.string "description", limit: 40 + t.string "delete_reason", limit: 100 + t.string "description", limit: 40 t.datetime "created_at" t.datetime "updated_at" + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" + t.string "image_fingerprint" end add_index "screenshots", ["id", "approved"], name: "id_approved", using: :btree