From 1ce834391abfcf758a399ac54066ed2cb2422991 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 11:48:12 +0200 Subject: [PATCH 01/13] Add cloudinary gem, fix some Gemfile comments --- Gemfile | 66 +++++++++++++++++++---------------- Gemfile.lock | 20 +++++++++++ config/cloudinary.yml.example | 4 +++ 3 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 config/cloudinary.yml.example diff --git a/Gemfile b/Gemfile index 0295e6a9..4eb06437 100644 --- a/Gemfile +++ b/Gemfile @@ -21,14 +21,17 @@ gem 'rails-observers' # for tracking data changes gem 'paper_trail' -# Internationalizing gem , use gem according to version of your rails application -gem 'rails-i18n', '~> 4.0.0' # For 4.0.x +# for upload management +gem 'paperclip' + +# for internationalizing +gem 'rails-i18n', '~> 4.0.0' # as authentification framework gem 'devise' gem 'devise_ichain_authenticatable' -# to support openID authentication +# for openID authentication gem 'omniauth' gem 'omniauth-facebook' gem 'omniauth-openid' @@ -37,7 +40,8 @@ gem 'omniauth-github' # as authorization framework gem 'cancancan' -# to set roles + +# for roles gem 'rolify' # to show flash messages from ajax requests @@ -66,17 +70,16 @@ gem 'formtastic-bootstrap' gem 'formtastic', '~> 3.1.1' gem 'cocoon' -# frontend javascripts - # as the JavaScript library gem 'jquery-rails' +# frontend javascripts source 'https://rails-assets.org' do # for placeholder images gem 'rails-assets-holderjs' # for formating dates gem 'rails-assets-date.format' - # for or parsing, validating, manipulating, and formatting dates. + # for or parsing, validating, manipulating, and formatting dates gem 'rails-assets-momentjs' # for smooth scrolling gem 'rails-assets-jquery-smooth-scroll' @@ -97,8 +100,10 @@ end # as date picker gem 'bootstrap3-datetimepicker-rails', '~> 3.0.2' gem 'jquery-datatables-rails', '~> 2.2.1' + # for charts gem 'chart-js-rails' + # for displaying maps gem 'leaflet-rails' @@ -108,9 +113,6 @@ gem 'gravtastic' # for country selects gem 'country_select' -# for upload management -gem 'paperclip' - # as PDF generator gem 'prawn_rails' @@ -120,24 +122,21 @@ gem 'axlsx_rails' # as error catcher gem 'hoptoad_notifier', '~> 2.3' -# to make links faster. Read more: https://github.com/rails/turbolinks +# to make links faster gem 'turbolinks' # for JSON serialization of our API gem 'active_model_serializers' -# for icon fonts +# as icon font gem 'font-awesome-rails' -# for Markdown in description +# for markdown gem 'redcarpet' # as rdoc generator gem 'rdoc-generator-fivefish' -# for seeds -gem 'factory_girl_rails' - # for visitor tracking gem 'ahoy_matey' gem 'activeuuid' @@ -162,44 +161,51 @@ gem 'bootstrap-switch-rails', '~> 3.0.0' # for parsing OEmbed data gem 'ruby-oembed' -# Use guard and spring for testing in development +# for uploading images to the cloud +gem 'cloudinary' + group :development do - # rspec Guard rules + # to launch specs when files are modified gem 'guard-rspec', '~> 4.2.8' gem 'spring-commands-rspec' - # Get HoundCi comments locally + # for static code analisys gem 'rubocop' - # Silence rack assests messages + # to silence rack assests messages gem 'quiet_assets' - # Use sqlite3 as the database in development + # as database gem 'sqlite3' - # Use letter_opener to open mails in development + # to open mails gem 'letter_opener' - # Use letter_opener_web to open mails in browser (e.g. necessary for Vagrant) + # to open mails in browser gem 'letter_opener_web' - # mina is a blazing fast deployment system + # as deployment system gem 'mina' + # as debugger on error pages gem 'web-console', '~> 2.0' end -# Use rspec and capybara as testing framework group :test do - # We use coveralls for measuring test coverage - gem 'coveralls', require: false + # as test framework gem 'rspec-rails' - gem 'capybara' gem 'database_cleaner' + gem 'capybara' gem 'poltergeist' gem 'phantomjs', :require => 'phantomjs/poltergeist' - # Set of rails validations matchers to describe models + # for measuring test coverage + gem 'coveralls', require: false + # for describing models gem 'shoulda-matchers', require: false - # Extracted from RSpec 3 stub_model and mock_model + # for stubing/mocking models gem 'rspec-activemodel-mocks' + # to freeze time gem 'timecop' # for mocking external requests gem 'webmock' end group :development, :test do + # as debugger gem 'byebug' + # for seeds + gem 'factory_girl_rails' end diff --git a/Gemfile.lock b/Gemfile.lock index e029ca48..67214667 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,7 @@ GEM json awesome_nested_set (3.0.0.rc.5) activerecord (>= 4.0.0, < 5) + aws_cf_signer (0.1.3) axlsx (2.0.1) htmlentities (~> 4.3.1) nokogiri (>= 1.4.1) @@ -104,6 +105,9 @@ GEM climate_control (0.0.3) activesupport (>= 3.0) cliver (0.3.2) + cloudinary (1.1.6) + aws_cf_signer + rest-client cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) cocoon (1.2.6) @@ -151,6 +155,8 @@ GEM devise (>= 2.2) diff-lcs (1.2.5) docile (1.1.5) + domain_name (0.5.20160310) + unf (>= 0.0.5, < 1.0.0) erubis (2.7.0) execjs (2.6.0) factory_girl (4.5.0) @@ -194,6 +200,8 @@ GEM activesupport builder htmlentities (4.3.1) + http-cookie (1.0.2) + domain_name (~> 0.5) i18n (0.7.0) i18n_data (0.7.0) inversion (0.12.3) @@ -250,6 +258,7 @@ GEM multi_xml (0.5.5) multipart-post (2.0.0) mysql2 (0.4.2) + netrc (0.11.0) nio4r (1.2.1) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) @@ -384,6 +393,10 @@ GEM request_store (1.0.6) responders (2.1.1) railties (>= 4.2.0, < 5.1) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) rolify (5.0.0) rspec (3.0.0) rspec-core (~> 3.0.0) @@ -466,6 +479,9 @@ GEM thread_safe (~> 0.1) uglifier (3.0.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.2) unicode-display_width (0.3.1) unicode_utils (1.4.0) unobtrusive_flash (3.1.0) @@ -511,6 +527,7 @@ DEPENDENCIES cancancan capybara chart-js-rails + cloudinary cocoon country_select coveralls @@ -581,3 +598,6 @@ DEPENDENCIES web-console (~> 2.0) webmock whenever + +BUNDLED WITH + 1.11.2 diff --git a/config/cloudinary.yml.example b/config/cloudinary.yml.example new file mode 100644 index 00000000..ce0dec09 --- /dev/null +++ b/config/cloudinary.yml.example @@ -0,0 +1,4 @@ +production: + cloud_name: "sample" + api_key: "874837483274837" + api_secret: "a676b67565c6767a6767d6767f676fe1" From ae55c2772fddeb8e0161caac0a2808141d620c47 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 12:36:38 +0200 Subject: [PATCH 02/13] Remove danging :photos table and other photo cruft --- app/controllers/admin/conference_controller.rb | 2 +- app/controllers/conference_controller.rb | 5 ----- app/models/conference.rb | 2 -- app/models/photo.rb | 10 ---------- app/views/conference/_gallery_photo.html.haml | 7 ------- db/migrate/20160427101444_remove_photos.rb | 13 +++++++++++++ db/schema.rb | 13 +------------ 7 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 app/models/photo.rb delete mode 100644 app/views/conference/_gallery_photo.html.haml create mode 100644 db/migrate/20160427101444_remove_photos.rb diff --git a/app/controllers/admin/conference_controller.rb b/app/controllers/admin/conference_controller.rb index def55090..6cdd4c49 100644 --- a/app/controllers/admin/conference_controller.rb +++ b/app/controllers/admin/conference_controller.rb @@ -185,7 +185,7 @@ module Admin :use_difficulty_levels, :use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers, :color, :sponsorship_levels_attributes, :sponsors_attributes, - :photos_attributes, :targets, :targets_attributes, + :targets, :targets_attributes, :campaigns, :campaigns_attributes, :registration_limit) end end diff --git a/app/controllers/conference_controller.rb b/app/controllers/conference_controller.rb index 16aa382f..eecaf71d 100644 --- a/app/controllers/conference_controller.rb +++ b/app/controllers/conference_controller.rb @@ -23,11 +23,6 @@ class ConferenceController < ApplicationController end end - def gallery_photos - @photos = @conference.photos - render 'photos', formats: [:js] - end - private def respond_to_options diff --git a/app/models/conference.rb b/app/models/conference.rb index 0a2ff5d6..3fbd0a90 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -30,7 +30,6 @@ class Conference < ActiveRecord::Base has_many :vpositions, dependent: :destroy has_many :sponsorship_levels, -> { order('position ASC') }, dependent: :destroy has_many :sponsors, dependent: :destroy - has_many :photos, dependent: :destroy has_many :targets, dependent: :destroy has_many :campaigns, dependent: :destroy has_many :commercials, as: :commercialable, dependent: :destroy @@ -44,7 +43,6 @@ class Conference < ActiveRecord::Base accepts_nested_attributes_for :questions, allow_destroy: true accepts_nested_attributes_for :vdays, allow_destroy: true accepts_nested_attributes_for :vpositions, allow_destroy: true - accepts_nested_attributes_for :photos, allow_destroy: true accepts_nested_attributes_for :targets, allow_destroy: true accepts_nested_attributes_for :campaigns, allow_destroy: true diff --git a/app/models/photo.rb b/app/models/photo.rb deleted file mode 100644 index 91ab1dea..00000000 --- a/app/models/photo.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Photo < ActiveRecord::Base - belongs_to :conference - validates_presence_of :picture - has_attached_file :picture, - styles: { thumb: '100x100>', large: '300x300>', banner: '600x300>' } - - validates_attachment_content_type :picture, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } -end diff --git a/app/views/conference/_gallery_photo.html.haml b/app/views/conference/_gallery_photo.html.haml deleted file mode 100644 index db013bd3..00000000 --- a/app/views/conference/_gallery_photo.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -- photos.each_with_index do |photo,index| - %div.item{ class: (index==0? 'active' : '') } - = image_tag(photo.picture(:banner)) - - unless photo.description.blank? - %div.carousel-caption - .lead - = photo.description diff --git a/db/migrate/20160427101444_remove_photos.rb b/db/migrate/20160427101444_remove_photos.rb new file mode 100644 index 00000000..966cf187 --- /dev/null +++ b/db/migrate/20160427101444_remove_photos.rb @@ -0,0 +1,13 @@ +class RemovePhotos < ActiveRecord::Migration + def change + drop_table :photos do |t| + t.text :description + t.string :picture_file_name + t.string :picture_content_type + t.integer :picture_file_size + t.datetime :picture_updated_at + t.belongs_to :conference + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 97d13714..3258f8e2 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: 20160403214841) do +ActiveRecord::Schema.define(version: 20160427101444) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -257,17 +257,6 @@ ActiveRecord::Schema.define(version: 20160403214841) do t.datetime "updated_at" end - create_table "photos", force: :cascade do |t| - t.text "description" - t.string "picture_file_name" - t.string "picture_content_type" - t.integer "picture_file_size" - t.datetime "picture_updated_at" - t.integer "conference_id" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "programs", force: :cascade do |t| t.integer "conference_id" t.integer "rating", default: 0 From d55d206b9310ec6fef22fca5e9cc39d2b94928bf Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 12:38:37 +0200 Subject: [PATCH 03/13] Switch to carrierwave for upload management --- Gemfile | 2 +- Gemfile.lock | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 4eb06437..789f5f77 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'rails-observers' gem 'paper_trail' # for upload management -gem 'paperclip' +gem 'carrierwave' # for internationalizing gem 'rails-i18n', '~> 4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 67214667..28b8c64e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,11 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + carrierwave (0.11.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) celluloid (0.15.2) timers (~> 1.1.0) celluloid-io (0.15.0) @@ -102,14 +107,10 @@ GEM chart-js-rails (0.0.6) railties (> 3.1) chronic (0.10.2) - climate_control (0.0.3) - activesupport (>= 3.0) cliver (0.3.2) cloudinary (1.1.6) aws_cf_signer rest-client - cocaine (0.5.8) - climate_control (>= 0.0.3, < 1.0) cocoon (1.2.6) coderay (1.1.0) coffee-rails (4.1.1) @@ -236,7 +237,6 @@ GEM mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (2.99.1) - mimemagic (0.3.0) mina (0.3.8) open4 (~> 1.3.4) rake @@ -292,12 +292,6 @@ GEM paper_trail (3.0.1) activerecord (>= 3.0, < 5.0) activesupport (>= 3.0, < 5.0) - paperclip (4.3.2) - activemodel (>= 3.2.0) - activesupport (>= 3.2.0) - cocaine (~> 0.5.5) - mime-types - mimemagic (= 0.3.0) parser (2.3.0.3) ast (~> 2.2) pdf-core (0.2.5) @@ -526,6 +520,7 @@ DEPENDENCIES byebug cancancan capybara + carrierwave chart-js-rails cloudinary cocoon @@ -558,7 +553,6 @@ DEPENDENCIES omniauth-google-oauth2 omniauth-openid paper_trail - paperclip phantomjs piwik_analytics (~> 1.0.1) poltergeist From e3c457267cc3f17387e2b70b03b5a6dd51b87189 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:04:15 +0200 Subject: [PATCH 04/13] Also require mini_magick for image manipulation --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 789f5f77..34b113c6 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem 'paper_trail' # for upload management gem 'carrierwave' +gem 'mini_magick' # for internationalizing gem 'rails-i18n', '~> 4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 28b8c64e..1dc442e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -240,6 +240,7 @@ GEM mina (0.3.8) open4 (~> 1.3.4) rake + mini_magick (4.5.1) mini_portile2 (2.0.0) minitest (5.8.4) momentjs-rails (2.8.1) @@ -545,6 +546,7 @@ DEPENDENCIES letter_opener letter_opener_web mina + mini_magick money-rails mysql2 omniauth From cea9081347c4f61ef90674a4a571b9c7f2a6a15a Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:09:31 +0200 Subject: [PATCH 05/13] A paperclip compatible carrierwave uploader --- app/uploaders/picture_uploader.rb | 81 ++++++++++++++++++++++++++++++ config/initializers/carrierwave.rb | 4 ++ 2 files changed, 85 insertions(+) create mode 100644 app/uploaders/picture_uploader.rb create mode 100644 config/initializers/carrierwave.rb diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb new file mode 100644 index 00000000..ac25565b --- /dev/null +++ b/app/uploaders/picture_uploader.rb @@ -0,0 +1,81 @@ +# encoding: utf-8 + +class PictureUploader < CarrierWave::Uploader::Base + include CarrierWave::MiniMagick + include CarrierWave::Compatibility::Paperclip + + def paperclip_path + "system/#{object_class_name}/#{extra_store_dir}/#{id_partition}/:style/:basename.:extension" + end + + def object_class_name + model.class.to_s.underscore.pluralize + end + + # compatibility with our paperclip storage paths.. + def extra_store_dir + case object_class_name + when 'conferences' + 'logos' + when 'lodgings' + 'photos' + when 'sponsors' + 'logos' + when 'venues' + 'photos' + else mounted_as + end + end + + # Returns the id of the instance in a split path form. e.g. returns + # 000/001/234 for an id of 1234. Stolen from paperclip... + def id_partition + ('%09d'.freeze % model.id).scan(/\d{3}/).join('/'.freeze) + end + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "system/#{object_class_name}/#{mounted_as}/#{model.id}" + end + + # Create different versions of your uploaded files: + version :large do + process resize_to_fit: [300, 300] + end + + version :thumb, from_version: :large do + process resize_to_fit: [100, 100] + end + + version :first, if: :sponsor? + version :first do + process resize_to_fill: [320, 180] + end + + version :second, if: :sponsor? + version :second, from_version: :first do + process resize_to_fill: [320, 150] + end + + version :others, if: :sponsor? + version :others, from_version: :second do + process resize_to_fill: [320, 120] + end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %w(jpg jpeg gif png) + end + + def content_type_whitelist + %r{/image\//} + end + + private + + def sponsor?(_picture) + object_class_name == 'sponsors' + end +end diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb new file mode 100644 index 00000000..7997fb57 --- /dev/null +++ b/config/initializers/carrierwave.rb @@ -0,0 +1,4 @@ +CarrierWave.configure do |config| + config.storage = :file + config.cache_dir = "#{Rails.root}/tmp/uploads" +end From 40023044afeb83d4556551efa9d8dc37ec502d62 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:17:12 +0200 Subject: [PATCH 06/13] Use PictureUploader on Conference --- app/controllers/admin/conference_controller.rb | 2 +- app/models/conference.rb | 7 +------ app/serializers/conference_serializer.rb | 2 +- app/views/admin/conference/edit.html.haml | 9 ++++++--- app/views/conference/_conference_details.html.haml | 2 +- app/views/conference/show.html.haml | 2 +- db/migrate/20160427104236_add_pictures.rb | 8 ++++++++ db/schema.rb | 6 +++++- 8 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20160427104236_add_pictures.rb diff --git a/app/controllers/admin/conference_controller.rb b/app/controllers/admin/conference_controller.rb index 6cdd4c49..232d0eec 100644 --- a/app/controllers/admin/conference_controller.rb +++ b/app/controllers/admin/conference_controller.rb @@ -180,7 +180,7 @@ module Admin params.require(:conference).permit(:title, :short_title, :description, :timezone, :start_date, :end_date, :rooms_attributes, :tracks_attributes, :tickets_attributes, :event_types_attributes, - :logo, :questions_attributes, + :picture, :picture_cache, :questions_attributes, :question_ids, :answers_attributes, :answer_ids, :difficulty_levels_attributes, :use_difficulty_levels, :use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers, :color, diff --git a/app/models/conference.rb b/app/models/conference.rb index 3fbd0a90..f0b73047 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -46,12 +46,7 @@ class Conference < ActiveRecord::Base accepts_nested_attributes_for :targets, allow_destroy: true accepts_nested_attributes_for :campaigns, allow_destroy: true - has_attached_file :logo, - styles: { thumb: '100x100>', large: '300x300>' } - - validates_attachment_content_type :logo, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + mount_uploader :picture, PictureUploader, mount_on: :logo_file_name validates_presence_of :title, :short_title, diff --git a/app/serializers/conference_serializer.rb b/app/serializers/conference_serializer.rb index aec0d76e..b2b80c28 100644 --- a/app/serializers/conference_serializer.rb +++ b/app/serializers/conference_serializer.rb @@ -1,5 +1,5 @@ class ConferenceSerializer < ActiveModel::Serializer - attributes :short_title, :title, :description, :start_date, :end_date, :logo, + attributes :short_title, :title, :description, :start_date, :end_date, :picture_url, :difficulty_levels, :event_types, :rooms, :tracks, :date_range, :revision diff --git a/app/views/admin/conference/edit.html.haml b/app/views/admin/conference/edit.html.haml index cbbfb3e7..dfc6d72a 100644 --- a/app/views/admin/conference/edit.html.haml +++ b/app/views/admin/conference/edit.html.haml @@ -11,9 +11,12 @@ = f.input :short_title, :hint => "A short title, e.g. 'oSC14', to be used in URLs" = f.input :description, hint: markdown_hint('A description of the conference.'), input_html: { rows: 5, data: { provide: 'markdown-editable' } } = f.input :color, :hint => "The color will be used eg for the dashboard.", :input_html => {:size => 6, :type => "color"} - - if !@conference.logo.blank? - = image_tag @conference.logo(:thumb) - = f.input :logo, :label => "Conference Logo", :hint => "This will be displayed on the front page." + = f.label 'Conference Logo' + %br + - if @conference.picture? + = image_tag @conference.picture.thumb.url + = f.input :picture, :label => false, :hint => "This will be displayed on the front page." + = f.hidden_field :picture_cache = f.inputs :name => "Scheduling" do = f.input :timezone, :as => :time_zone, :hint => "The conference time zone" = f.input :start_date, :as => :string, :input_html => { :id => "conference-start-datepicker", :readonly => "readonly" } diff --git a/app/views/conference/_conference_details.html.haml b/app/views/conference/_conference_details.html.haml index d3c07658..f8e17794 100644 --- a/app/views/conference/_conference_details.html.haml +++ b/app/views/conference/_conference_details.html.haml @@ -3,7 +3,7 @@ .well .row .col-md-4.text-center - = image_tag(conference.logo(:original), class: 'img-responsive') if conference.logo? + = image_tag(conference.picture_url, class: 'img-responsive') if conference.picture? .col-md-6 %h3 = conference.title diff --git a/app/views/conference/show.html.haml b/app/views/conference/show.html.haml index 63920eb6..071f8f7a 100644 --- a/app/views/conference/show.html.haml +++ b/app/views/conference/show.html.haml @@ -9,7 +9,7 @@ .col-md-8.col-md-offset-2#header .row .col-md-4 - = image_tag(@conference.logo(:original), class: 'img-responsive img-center', id: 'splash-logo') if @conference.logo? + = image_tag(@conference.picture_url, class: 'img-responsive img-center', id: 'splash-logo') if @conference.picture? .col-md-8 %h1 = @conference.title diff --git a/db/migrate/20160427104236_add_pictures.rb b/db/migrate/20160427104236_add_pictures.rb new file mode 100644 index 00000000..5a56da9c --- /dev/null +++ b/db/migrate/20160427104236_add_pictures.rb @@ -0,0 +1,8 @@ +class AddPictures < ActiveRecord::Migration + def change + add_column :conferences, :picture, :string + add_column :lodgings, :picture, :string + add_column :sponsors, :picture, :string + add_column :venues, :picture, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3258f8e2..00e93609 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: 20160427101444) do +ActiveRecord::Schema.define(version: 20160427104236) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -101,6 +101,7 @@ ActiveRecord::Schema.define(version: 20160427101444) do t.text "events_per_week" t.text "description" t.integer "registration_limit", default: 0 + t.string "picture" end create_table "conferences_questions", id: false, force: :cascade do |t| @@ -246,6 +247,7 @@ ActiveRecord::Schema.define(version: 20160427101444) do t.datetime "updated_at" t.string "website_link" t.integer "conference_id" + t.string "picture" end create_table "openids", force: :cascade do |t| @@ -366,6 +368,7 @@ ActiveRecord::Schema.define(version: 20160427101444) do t.integer "conference_id" t.datetime "created_at" t.datetime "updated_at" + t.string "picture" end create_table "sponsorship_levels", force: :cascade do |t| @@ -498,6 +501,7 @@ ActiveRecord::Schema.define(version: 20160427101444) do t.string "latitude" t.string "longitude" t.integer "conference_id" + t.string "picture" end create_table "versions", force: :cascade do |t| From 0ad3ff01c3554bdf7ba0958cd77ad5224100328c Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:27:33 +0200 Subject: [PATCH 07/13] Use PictureUploader on Lodging --- app/controllers/admin/lodgings_controller.rb | 2 +- app/models/lodging.rb | 7 +------ app/views/admin/lodgings/_form.html.haml | 6 +++--- app/views/admin/lodgings/index.html.haml | 6 +++--- app/views/conference/_lodging.html.haml | 7 +++---- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/controllers/admin/lodgings_controller.rb b/app/controllers/admin/lodgings_controller.rb index 5e94d53a..e128dcd5 100644 --- a/app/controllers/admin/lodgings_controller.rb +++ b/app/controllers/admin/lodgings_controller.rb @@ -47,7 +47,7 @@ module Admin private def lodging_params - params.require(:lodging).permit(:name, :description, :photo, :website_link, :conference_id) + params.require(:lodging).permit(:name, :description, :picture, :picture_cache, :website_link, :conference_id) end end end diff --git a/app/models/lodging.rb b/app/models/lodging.rb index aa01505c..48031eba 100644 --- a/app/models/lodging.rb +++ b/app/models/lodging.rb @@ -3,10 +3,5 @@ class Lodging < ActiveRecord::Base validates :name, presence: true - has_attached_file :photo, - styles: { thumb: '100x100>', large: '300x300>' } - - validates_attachment_content_type :photo, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + mount_uploader :picture, PictureUploader, mount_on: :photo_file_name end diff --git a/app/views/admin/lodgings/_form.html.haml b/app/views/admin/lodgings/_form.html.haml index d34a1b8c..d5ab72e5 100644 --- a/app/views/admin/lodgings/_form.html.haml +++ b/app/views/admin/lodgings/_form.html.haml @@ -12,8 +12,8 @@ = f.input :name = f.input :website_link = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint - - unless @lodging.photo.blank? - = image_tag @lodging.photo(:thumb) - = f.input :photo + - if @lodging.picture? + = image_tag @lodging.picture.thumb.url + = f.input :picture %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/lodgings/index.html.haml b/app/views/admin/lodgings/index.html.haml index 0775b7b9..1f3a89fb 100644 --- a/app/views/admin/lodgings/index.html.haml +++ b/app/views/admin/lodgings/index.html.haml @@ -10,15 +10,15 @@ - slice.each do |lodging| .col-md-4 .thumbnail - - if lodging.photo.blank? + - if !lodging.picture? %p.text-center %i.fa.fa-home.fa-5x - else -if lodging.website_link.present? = link_to(lodging.website_link, class: 'thumbnail') do - = image_tag lodging.photo(:thumb), class: 'img-responsive img-lodging' + = image_tag lodging.picture.thumb, class: 'img-responsive img-lodging' - else - = image_tag lodging.photo(:thumb), class: 'img-responsive img-lodging' + = image_tag lodging.picture.thumb, class: 'img-responsive img-lodging' .caption %h3.text-center = lodging.name diff --git a/app/views/conference/_lodging.html.haml b/app/views/conference/_lodging.html.haml index 7d603a68..ca30edc0 100644 --- a/app/views/conference/_lodging.html.haml +++ b/app/views/conference/_lodging.html.haml @@ -13,18 +13,17 @@ - slice.each do |lodging| .col-md-4.col-sm-4.ticket.col-centered.col-top .thumbnail - - if lodging.photo.blank? + - if !lodging.picture? %p.text-center %i.fa.fa-home.fa-5x - else -if lodging.website_link.present? = link_to(lodging.website_link, class: 'thumbnail') do - = image_tag lodging.photo(:large), class: 'img-responsive img-lodging' + = image_tag lodging.picture.large.url, class: 'img-responsive img-lodging' - else - = image_tag lodging.photo(:large), class: 'img-responsive img-lodging' + = image_tag lodging.picture.large.url, class: 'img-responsive img-lodging' .caption %h3.text-center = lodging.name -if lodging.description.present? = markdown(lodging.description) - From f1f5fc1cd474798e379bbda4ee8f5d211ef2c50e Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:55:39 +0200 Subject: [PATCH 08/13] Use PictureUploader on Sponsor --- app/controllers/admin/sponsors_controller.rb | 2 +- app/helpers/sponsors_helper.rb | 6 +++--- app/models/sponsor.rb | 17 ++--------------- app/uploaders/picture_uploader.rb | 6 +++--- app/views/admin/sponsors/_form.html.haml | 4 ++-- app/views/admin/sponsors/index.html.haml | 2 +- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index b7164900..2ee51762 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -49,7 +49,7 @@ module Admin private def sponsor_params - params.require(:sponsor).permit(:name, :description, :website_url, :logo, :sponsorship_level_id, :conference_id) + params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id) end end end diff --git a/app/helpers/sponsors_helper.rb b/app/helpers/sponsors_helper.rb index e827c1fe..4a21c9cd 100644 --- a/app/helpers/sponsors_helper.rb +++ b/app/helpers/sponsors_helper.rb @@ -2,11 +2,11 @@ module SponsorsHelper # returns the url to be used for logo on basis of sponsorship level position def get_logo(sponsor) if sponsor.sponsorship_level.position == 1 - sponsor.logo.url(:first) + sponsor.picture.first.url elsif sponsor.sponsorship_level.position == 2 - sponsor.logo.url(:second) + sponsor.picture.second.url else - sponsor.logo.url(:others) + sponsor.picture.others.url end end end diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 6b255886..7a843e63 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -1,21 +1,8 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference - has_attached_file :logo, - styles: { thumb: '100x100>', - first: '320x180>', - second: '320x150>', - others: '320x120>' }, - # places logo on a white background to maintain size - convert_options: { - first: '-background white -gravity center -extent 320x180', - second: '-background white -gravity center -extent 320x150', - others: '-background white -gravity center -extent 320x120' - } - validates_attachment_content_type :logo, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + mount_uploader :picture, PictureUploader, mount_on: :logo_file_name - validates_presence_of :name, :website_url, :sponsorship_level, :logo + validates_presence_of :name, :website_url, :sponsorship_level end diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index ac25565b..d4ad2a60 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -50,17 +50,17 @@ class PictureUploader < CarrierWave::Uploader::Base version :first, if: :sponsor? version :first do - process resize_to_fill: [320, 180] + process resize_and_pad: [320, 180, 'white'] end version :second, if: :sponsor? version :second, from_version: :first do - process resize_to_fill: [320, 150] + process resize_and_pad: [320, 150, 'white'] end version :others, if: :sponsor? version :others, from_version: :second do - process resize_to_fill: [320, 120] + process resize_and_pad: [320, 120, 'white'] end # Add a white list of extensions which are allowed to be uploaded. diff --git a/app/views/admin/sponsors/_form.html.haml b/app/views/admin/sponsors/_form.html.haml index 5ec2fbd0..ca78d8a5 100644 --- a/app/views/admin/sponsors/_form.html.haml +++ b/app/views/admin/sponsors/_form.html.haml @@ -11,8 +11,8 @@ = semantic_form_for(@sponsor, :url => (@sponsor.new_record? ? admin_conference_sponsors_path : admin_conference_sponsor_path(@conference.short_title, @sponsor))) do |f| = f.input :name = f.input :description - = image_tag f.object.logo(:thumb) if !f.object.logo.blank? - = f.input :logo + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels %p.text-right diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index d6364cb0..1c8f1077 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -19,7 +19,7 @@ - @conference.sponsors.each do |sponsor| %tr %td - = image_tag(sponsor.logo(:thumb), width: '20%') + = image_tag(sponsor.picture.thumb.url, width: '20%') %td = sponsor.name %td From 2a4de3e8694c94b50e287cccf00b9b274f79305c Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:59:34 +0200 Subject: [PATCH 09/13] Use PictureUploader on Venue --- app/controllers/admin/venues_controller.rb | 2 +- app/models/venue.rb | 6 +----- app/views/admin/venues/_form.html.haml | 8 ++++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/venues_controller.rb b/app/controllers/admin/venues_controller.rb index 903357dc..a049ea7c 100644 --- a/app/controllers/admin/venues_controller.rb +++ b/app/controllers/admin/venues_controller.rb @@ -44,7 +44,7 @@ module Admin private def venue_params - params.require(:venue).permit(:name, :street, :postalcode, :city, :country, :longitude, :latitude, :description, :website, :photo, :lodgings_attributes, :conference_id) + params.require(:venue).permit(:name, :street, :postalcode, :city, :country, :longitude, :latitude, :description, :website, :picture, :picture_cache, :lodgings_attributes, :conference_id) end end end diff --git a/app/models/venue.rb b/app/models/venue.rb index 41b12389..10cf4fcc 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -8,11 +8,7 @@ class Venue < ActiveRecord::Base validates :name, :street, :city, :country, presence: true validates :conference_id, presence: true, uniqueness: true - has_attached_file :photo, - styles: { thumb: '100x100>', large: '300x300>' } - validates_attachment_content_type :photo, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + mount_uploader :picture, PictureUploader, mount_on: :photo_file_name before_save :send_mail_notification diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml index 00f3e501..5b93cac0 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -8,7 +8,7 @@ = link_to 'Details', '#details-content', 'data-toggle' => 'tab' %li = link_to 'Commercials', '#commercials-content', 'data-toggle' => 'tab' - + .tab-content #details-content.tab-pane.active .col-md-8 @@ -16,9 +16,9 @@ = f.inputs :name, :website = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint = f.inputs :street, :postalcode, :city, :country, :latitude, :longitude - - unless @venue.photo.blank? - = image_tag @venue.photo(:thumb) - = f.input :photo + - if @venue.picture? + = image_tag @venue.picture.thumb.url + = f.input :picture = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } #commercials-content.tab-pane From a852a3b4a5cd22cb9db73294267ef24d84ab9767 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 16:03:29 +0200 Subject: [PATCH 10/13] Protect us from too large images --- Gemfile | 1 + Gemfile.lock | 7 +++++++ app/uploaders/picture_uploader.rb | 1 + 3 files changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index 34b113c6..0bf0e035 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem 'paper_trail' # for upload management gem 'carrierwave' gem 'mini_magick' +gem 'carrierwave-bombshelter' # for internationalizing gem 'rails-i18n', '~> 4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1dc442e2..02c56dec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,6 +99,10 @@ GEM activesupport (>= 3.2.0) json (>= 1.7) mime-types (>= 1.16) + carrierwave-bombshelter (0.1.1.6) + activesupport (>= 3.2.0) + carrierwave + fastimage celluloid (0.15.2) timers (~> 1.1.0) celluloid-io (0.15.0) @@ -167,6 +171,8 @@ GEM railties (>= 3.0.0) faraday (0.9.0) multipart-post (>= 1.2, < 3) + fastimage (2.0.0) + addressable (~> 2) ffi (1.9.3) font-awesome-rails (4.1.0.0) railties (>= 3.2, < 5.0) @@ -522,6 +528,7 @@ DEPENDENCIES cancancan capybara carrierwave + carrierwave-bombshelter chart-js-rails cloudinary cocoon diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index d4ad2a60..37e0aeb9 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -3,6 +3,7 @@ class PictureUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick include CarrierWave::Compatibility::Paperclip + include CarrierWave::BombShelter def paperclip_path "system/#{object_class_name}/#{extra_store_dir}/#{id_partition}/:style/:basename.:extension" From de486dc621a4bb2e839a79f3f690f7835efbf6d8 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 16:12:56 +0200 Subject: [PATCH 11/13] Oh My God. Close your eyes! Someone used a paperclip method in a migration. I'm too scared to look who, maybe it was me? --- config/initializers/fuckups.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 config/initializers/fuckups.rb diff --git a/config/initializers/fuckups.rb b/config/initializers/fuckups.rb new file mode 100644 index 00000000..3fdbe58e --- /dev/null +++ b/config/initializers/fuckups.rb @@ -0,0 +1,4 @@ +# Add methods here that slipped into migrations in the dark ages... +def remove_attachment(*args) + true +end From 86896cc46b0a2c2484a6ebdc17764b87ab17e0a1 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 16:40:23 +0200 Subject: [PATCH 12/13] And finally make use of Cloudinary if it's configured --- app/uploaders/picture_uploader.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index 37e0aeb9..171c2d23 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -5,6 +5,11 @@ class PictureUploader < CarrierWave::Uploader::Base include CarrierWave::Compatibility::Paperclip include CarrierWave::BombShelter + # use cloudinary if it's configured + if Cloudinary.config.cloud_name + include Cloudinary::CarrierWave + end + def paperclip_path "system/#{object_class_name}/#{extra_store_dir}/#{id_partition}/:style/:basename.:extension" end From 8fc57e34c9dba064c2e857f424b1acdecebaf83d Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 17:34:17 +0200 Subject: [PATCH 13/13] Adapt the spec --- config/initializers/carrierwave.rb | 1 + spec/factories/sponsors.rb | 11 +++++++---- spec/features/lodgings_spec.rb | 4 ++-- spec/features/sponsor_spec.rb | 2 +- spec/helpers/sponsor_helper_spec.rb | 6 +++--- spec/serializers/conference_serializer_spec.rb | 2 +- spec/views/conference/show.html.haml_spec.rb | 2 +- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 7997fb57..e9a315d8 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,4 +1,5 @@ CarrierWave.configure do |config| config.storage = :file config.cache_dir = "#{Rails.root}/tmp/uploads" + config.enable_processing = false if Rails.env.test? end diff --git a/spec/factories/sponsors.rb b/spec/factories/sponsors.rb index 961cb77f..51fcc183 100644 --- a/spec/factories/sponsors.rb +++ b/spec/factories/sponsors.rb @@ -5,11 +5,14 @@ FactoryGirl.define do name 'Example sponsor' website_url 'http://www.example.com' description 'Lorem Ipsum Dolor' - logo_file_name 'rails.jpg' - logo_file_size 2000 - logo_content_type 'image/jpeg' - logo_updated_at DateTime.current sponsorship_level conference + + after(:create) do |sponsor| + uploader = PictureUploader.new(sponsor, :picture) + File.open('app/assets/images/rails.png') { |f| uploader.store!(f) } + sponsor.logo_file_name = 'rails.png' + sponsor.save + end end end diff --git a/spec/features/lodgings_spec.rb b/spec/features/lodgings_spec.rb index 9bcaad6a..0731eff6 100644 --- a/spec/features/lodgings_spec.rb +++ b/spec/features/lodgings_spec.rb @@ -16,7 +16,7 @@ feature Lodging do fill_in 'lodging_name', with: 'New lodging' fill_in 'lodging_website_link', with: 'http:\\www.google.com' - attach_file 'Photo', path + attach_file 'Picture', path click_button 'Create Lodging' @@ -42,7 +42,7 @@ feature Lodging do fill_in 'lodging_name', with: 'New lodging' fill_in 'lodging_website_link', with: 'http:\\www.google.com' - attach_file 'Photo', path + attach_file 'Picture', path click_button 'Update Lodging' diff --git a/spec/features/sponsor_spec.rb b/spec/features/sponsor_spec.rb index b0454a52..df527ede 100644 --- a/spec/features/sponsor_spec.rb +++ b/spec/features/sponsor_spec.rb @@ -19,7 +19,7 @@ feature Sponsor do fill_in 'sponsor_name', with: 'SUSE' fill_in 'sponsor_description', with: 'The original provider of the enterprise Linux distribution' - attach_file 'Logo', path + attach_file 'Picture', path fill_in 'sponsor_website_url', with: 'http://www.suse.com' select('Platin', from: 'sponsor_sponsorship_level_id') diff --git a/spec/helpers/sponsor_helper_spec.rb b/spec/helpers/sponsor_helper_spec.rb index 492f9df5..ec9aff06 100644 --- a/spec/helpers/sponsor_helper_spec.rb +++ b/spec/helpers/sponsor_helper_spec.rb @@ -11,7 +11,7 @@ describe SponsorsHelper, type: :helper do end it 'returns correct url' do - expect(get_logo(sponsor)).to match %r{.*(\bfirst/rails.jpg\b)} + expect(get_logo(sponsor)).to match %r{.*(\bfirst/rails.png\b)} end end @@ -22,7 +22,7 @@ describe SponsorsHelper, type: :helper do end it 'returns correct url' do - expect(get_logo(sponsor)).to match %r{.*(\bsecond/rails.jpg\b)} + expect(get_logo(sponsor)).to match %r{.*(\bsecond/rails.png\b)} end end @@ -33,7 +33,7 @@ describe SponsorsHelper, type: :helper do end it 'returns correct url' do - expect(get_logo(sponsor)).to match %r{.*(\bothers/rails.jpg\b)} + expect(get_logo(sponsor)).to match %r{.*(\bothers/rails.png\b)} end end end diff --git a/spec/serializers/conference_serializer_spec.rb b/spec/serializers/conference_serializer_spec.rb index a7d52a52..1de2f887 100644 --- a/spec/serializers/conference_serializer_spec.rb +++ b/spec/serializers/conference_serializer_spec.rb @@ -16,7 +16,7 @@ describe ConferenceSerializer, type: :serializer do description: 'Lorem ipsum dolor sit', start_date: '2014-03-04', end_date: '2014-03-10', - logo: '/logos/original/missing.png', + picture_url: nil, difficulty_levels: [{id: 1, title: 'Easy', diff --git a/spec/views/conference/show.html.haml_spec.rb b/spec/views/conference/show.html.haml_spec.rb index 04951b64..18d485eb 100644 --- a/spec/views/conference/show.html.haml_spec.rb +++ b/spec/views/conference/show.html.haml_spec.rb @@ -60,7 +60,7 @@ describe 'conference/show.html.haml' do expect(rendered).to match(/example@example.com/) expect(rendered).to match(/www.example.com/) expect(rendered).to match(/Lorem Ipsum Dolor/) - expect(rendered).to match(/rails.jpg/) + expect(rendered).to match(/rails.png/) end it 'renders social media partial' do