From 4c96ba1e9ce6598f3b153f5cc87d1b155b1beb90 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 20 Feb 2024 02:27:07 +0200 Subject: [PATCH] Migrate from Refile and Carrierwave to ActiveStorage --- .gitignore | 1 + Gemfile | 13 --- Gemfile.lock | 79 ++---------------- app/assets/config/manifest.js | 6 ++ app/assets/images/avatar-placeholder.png | Bin 0 -> 2889 bytes .../javascripts/management/application.js | 1 - .../stylesheets/management/application.scss | 4 +- .../personal_profiles_controller.rb | 2 +- .../public/personal_profiles_controller.rb | 2 +- app/models/personal_profile.rb | 2 +- app/models/user.rb | 2 +- app/models/volunteer.rb | 2 +- app/uploaders/picture_uploader.rb | 53 ------------ app/views/management/events/_speaker.slim | 2 +- .../personal_profiles/_form.html.slim | 4 +- .../personal_profiles/index.html.slim | 5 +- .../personal_profiles/show.html.slim | 2 +- .../management/volunteers/_form.html.slim | 4 +- .../management/volunteers/index.html.slim | 4 +- .../management/volunteers/show.html.slim | 13 +-- .../team_notification.text.erb | 1 - config/application.rb | 2 +- config/environments/development.rb | 2 + config/initializers/assets.rb | 2 +- config/locales/management.bg.yml | 2 + ...te_active_storage_tables.active_storage.rb | 57 +++++++++++++ db/seeds.rb | 12 +-- .../javascripts/initfest/application.js | 1 + .../views/public/personal_profiles/_form.slim | 7 +- .../views/public/volunteers/_form.slim | 4 +- public/uploads/.keep | 0 public/uploads/tmp/.keep | 0 spec/models/volunteership_spec.rb | 5 -- spec/support/feature_helpers.rb | 2 +- spec/support/matchers/has_errors_on.rb | 2 +- 35 files changed, 118 insertions(+), 182 deletions(-) create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/avatar-placeholder.png delete mode 100644 app/uploaders/picture_uploader.rb create mode 100644 db/migrate/20240219234146_create_active_storage_tables.active_storage.rb delete mode 100644 public/uploads/.keep delete mode 100644 public/uploads/tmp/.keep delete mode 100644 spec/models/volunteership_spec.rb diff --git a/.gitignore b/.gitignore index 9d4fc89..3640ed2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ .sass-cache/ /coverage/ /db/structure.sql +/storage/ \ No newline at end of file diff --git a/Gemfile b/Gemfile index eae29c1..e265b2e 100644 --- a/Gemfile +++ b/Gemfile @@ -26,15 +26,6 @@ gem "simple_form" gem "phony" gem "phony_rails" -# Picture uploads -gem "carrierwave" -# gem 'rmagick' -gem "mini_magick" - -gem "refile", git: "https://github.com/refile/refile", require: ["refile/rails", "refile/simple_form"] -gem "refile-mini_magick" -gem "image_processing" - gem "puma", group: :production gem "globalize" @@ -74,10 +65,6 @@ group :development do gem "pry-rails" # gem 'hirb' gem "awesome_print" - gem "capistrano" - gem "capistrano-rails" - gem 'capistrano-rvm' - gem "capistrano3-puma" gem "better_errors" gem "binding_of_caller" end diff --git a/Gemfile.lock b/Gemfile.lock index 3a3aaa8..d2b1047 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,3 @@ -GIT - remote: https://github.com/refile/refile - revision: c4ac577c6fdad92bc079a62a0e82888319daedc8 - specs: - refile (0.7.0) - mime-types - sinatra (>= 2.0.0, <= 3.0.0) - GEM remote: https://rubygems.org/ specs: @@ -89,8 +81,6 @@ GEM tzinfo (~> 2.0) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - airbrussh (1.5.1) - sshkit (>= 1.6.1, != 1.7.0) ast (2.4.2) autoprefixer-rails (10.4.16.0) execjs (~> 2) @@ -122,23 +112,6 @@ GEM railties (>= 3.1) builder (3.2.4) byebug (11.1.3) - capistrano (3.18.0) - airbrussh (>= 1.0.0) - i18n - rake (>= 10.0.0) - sshkit (>= 1.9.0) - capistrano-bundler (2.1.0) - capistrano (~> 3.1) - capistrano-rails (1.6.3) - capistrano (~> 3.1) - capistrano-bundler (>= 1.1, < 3) - capistrano-rvm (0.1.2) - capistrano (~> 3.0) - sshkit (~> 1.2) - capistrano3-puma (5.2.0) - capistrano (~> 3.7) - capistrano-bundler - puma (>= 4.0, < 6.0) capybara (3.40.0) addressable matrix @@ -291,16 +264,11 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) - mime-types (3.5.2) - mime-types-data (~> 3.2015) - mime-types-data (3.2024.0206) mini_magick (4.12.0) mini_mime (1.1.5) mini_portile2 (2.8.5) minitest (5.22.2) msgpack (1.7.2) - mustermann (3.0.0) - ruby2_keywords (~> 0.0.1) mutex_m (0.2.0) nenv (0.3.0) nested_form (0.3.2) @@ -313,13 +281,8 @@ GEM net-protocol net-protocol (0.2.2) timeout - net-scp (4.0.0) - net-ssh (>= 2.6.5, < 8.0.0) - net-sftp (4.0.0) - net-ssh (>= 5.0.0, < 8.0.0) net-smtp (0.4.0.1) net-protocol - net-ssh (7.2.1) nio4r (2.7.0) nokogiri (1.16.2) mini_portile2 (~> 2.8.2) @@ -345,19 +308,17 @@ GEM psych (5.1.2) stringio public_suffix (5.0.4) - puma (5.6.8) + puma (6.4.2) nio4r (~> 2.0) racc (1.7.3) - rack (2.2.8) - rack-protection (3.0.0) - rack - rack-session (1.0.2) - rack (< 3) + rack (3.0.9) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) - rack (< 3) - webrick + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) rails (7.1.3) actioncable (= 7.1.3) actionmailbox (= 7.1.3) @@ -403,9 +364,6 @@ GEM ffi (~> 1.0) rdoc (6.6.2) psych (>= 4.0.0) - refile-mini_magick (0.2.0) - mini_magick (~> 4.0) - refile (~> 0.5) regexp_parser (2.9.0) reline (0.4.2) io-console (~> 0.5) @@ -480,7 +438,7 @@ GEM sprockets-rails tilt search_object (1.2.5) - selenium-webdriver (4.18.0) + selenium-webdriver (4.18.1) base64 (~> 0.2) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) @@ -495,11 +453,6 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - sinatra (3.0.0) - mustermann (~> 3.0) - rack (~> 2.2, >= 2.2.4) - rack-protection (= 3.0.0) - tilt (~> 2.0) slim (5.2.1) temple (~> 0.10.0) tilt (>= 2.1.0) @@ -520,11 +473,6 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.7.2) mini_portile2 (~> 2.8.0) - sshkit (1.22.0) - mutex_m - net-scp (>= 1.1.2) - net-sftp (>= 2.1.2) - net-ssh (>= 2.8.0) ssrf_filter (1.1.2) standard (1.34.0) language_server-protocol (~> 3.17.0.2) @@ -578,12 +526,7 @@ DEPENDENCIES bootstrap-sass-extras bootswatch-rails byebug - capistrano - capistrano-rails - capistrano-rvm - capistrano3-puma capybara - carrierwave coffee-rails copy_carrierwave_file database_cleaner @@ -599,11 +542,9 @@ DEPENDENCIES guard-rspec i18n-tasks icalendar - image_processing jbuilder jquery-datatables-rails jquery-rails - mini_magick nested_form pg phony @@ -614,8 +555,6 @@ DEPENDENCIES rails-erd rails-i18n raphael-rails - refile! - refile-mini_magick rqrcode rspec-rails sass-rails @@ -633,4 +572,4 @@ DEPENDENCIES yaml_db BUNDLED WITH - 2.4.12 + 2.5.6 diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..7f73fde --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,6 @@ +//= link_tree ../images +//= link_tree ../../../lib/initfest/assets/images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css +//= link initfest/application.css +//= link initfest/application.js diff --git a/app/assets/images/avatar-placeholder.png b/app/assets/images/avatar-placeholder.png new file mode 100644 index 0000000000000000000000000000000000000000..786c84000c505f5bd284b6429bf2b74e01d39e75 GIT binary patch literal 2889 zcmV-P3%2x$P)EX>4Tx04R}tkv&MmKpe$i(@I5J1nnT=kfA!+MMVUcT7@E12(?114knj=L6e3g z#l=x@EjakGSaoo5*44pP5ClI!oE@ALU8KbSrG*wT9vt`M-Mz=%J3weum}UjyfTr7K zI++l&xm7XviU7hGz${`ivy3@OO2Kn{-NVP%yBN>%KKJJct9gq7K9M-i4AUmwAfDc| z4bJ<-5mu5_;&bA0lP*a7$aST~Z=8!R3p_JoX43P-5n{2}#Yz{mlBp3-5l2-`r+gvX zVwLk2XRT6W?R)YUhVuH#GS_L2Ac;jRL4pVcHIz|-jTo&uDHhVSpYZSxyMBpW3c1Q) z4t02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{00|*UL_t(&-pyJ|ZyQGv{;Fq&VUI3dq-h=>-9iHVCLIy zQMr~IS(f3)AAiJnJjQ4=LLA2)0NU>5T#rO-45`S+uj*R$w!m)Nxl!oTH#avZiUJoG z7x?0fFZ_y@W$9P4p0}->rYXMu`fF&dadmYCt+juC+l@nyXwN$p>6-2(S(br_u-Rwx|DPN zyj(6TOC^%^H9 zCoqPCZ2xYI%{j_mPlx2y@c!GxyA0o>#q-hEOh@z;K*9bN5v1wj)A;K;Tg{yLNbA$c;eV-HF zcetcyjPZ%`@#Dvh{Z7!4=6=j9m5+8)kv4k7aSW|BwASeN`_Nhkx#Ha|66PAN$Yz=j zkYyQ0qfsL{`V3D1P^$!S|LI!75Rjlrm0u9 zzK$R)mOXkRDcG58+8oOzxh%^t7z~gkiHBR3_Ye5?==b}0^5ltkxlZ&%6TvFdNSy?+ zt)Nm0o6QDAQQ-9S)aQ#v1@pnm5VY1PiUMU>B97yRMQSCKH6IZmTv-HfPg>4D-GlQy zZ`2!B8Tu&J5ZL^4eSPiS_x2(K;tD#q$jkyZcT<3Hq-lz)tE)Q6eIRl*?O_)z&+`UX zYb)CpDz+$n$lP6CaHG^XaA3BPn@D!*sm$~U&&K6d+U$-gB zErwaSkx~jpQTXdzz{^L7c7fpX@)Bv9HjpahaUuXyc#lhn*qy<{V_Iup^*OqI3qC)B zYrT2%#+SfhkbAkT`vmWV5yZwpjt=$6zqP@$nJfCy6-PBO-Y9>J?tUevQ59L(e2S%ZspHuPKTEEWU5m zg<4%56|FT!qmf6LA}^36(R-0b5y5h~#A30)csyyegF-Im!NoEyh&a?DC`Z(G#Yns5 z6DG(!&oLYh@$0X@;-{BCfgxZKKv`lZRAIjV14O7XSqPWQ75@F7|Jr6kCAw_!2m5LfmJhX^PX+Q#^X~2rpi|z-%^axR$f5?*mKK|3%Q$ zaNY1-{VbQkwbp*$y`(HlUnz#2le^-qi!sD;jQ#z6L{a2}d}oijqyHQ;Gf*K{+Zyf$ zBJw4z+s^YG+wB%7Cnt#G7{+LTnY>i0))k*pYOd>wNj;m-zYTpRrgh@ZiA%e?08Y z3yc4B$fr8H%F7Y&OI3@p08`j=(HUm!f;ncu~7824Led#Fz z5aHtwBCyoie7#=d_3PL8{kPwtB8A~_gh(kwQS6PYl(ML$nGsdrI+RjaE|*|t?C(fgHCVCpg5%?393CEGyV>IW>>P{50@LXfAhH%= zwqJEOn+?AI{%=Urp@&_^K-(W}K8X^+v%|#dD36n2JRalu^XIsDv%t%jFEN=+Ec_A? z)>l_}`t&J!y?&!uvOzDMU!Ok7sDQ1Db%(tH7GO4;;px+-nE&>hC5@=M>jwu1x3YNf z{7-6y(6xl_?nc^JQkYJs_~n;hpa4OsHOAv{1#i^(rRfh);ojY2`(p!}CI*86jLYms zYaAaRqbLgWdcDpVp#LjnEEt%|-R-9h-Gdm54E=uJX6Qd67CvCGFrcXV%>ZFGn<9=7 zL6;h7nxZUb div { display: inline-block; } -} \ No newline at end of file +} diff --git a/app/controllers/management/personal_profiles_controller.rb b/app/controllers/management/personal_profiles_controller.rb index f32a450..5a7d4f1 100644 --- a/app/controllers/management/personal_profiles_controller.rb +++ b/app/controllers/management/personal_profiles_controller.rb @@ -53,7 +53,7 @@ module Management @conference = find_conference @profile = find_profile - if @profile.update_attributes(profile_params) + if @profile.update(profile_params) redirect_to [:management, @conference, @profile] else render action: "edit" diff --git a/app/controllers/public/personal_profiles_controller.rb b/app/controllers/public/personal_profiles_controller.rb index 1aff08b..9f3a5dd 100644 --- a/app/controllers/public/personal_profiles_controller.rb +++ b/app/controllers/public/personal_profiles_controller.rb @@ -20,7 +20,7 @@ module Public def update @profile = current_user.personal_profile(current_conference) - if @profile.update_attributes(profile_params) + if @profile.update(profile_params) flash[:notice] = t("views.personal_profiles.successfully_updated") redirect_to root_path else diff --git a/app/models/personal_profile.rb b/app/models/personal_profile.rb index 68a30ef..5a88d3b 100644 --- a/app/models/personal_profile.rb +++ b/app/models/personal_profile.rb @@ -13,7 +13,7 @@ class PersonalProfile < ActiveRecord::Base phony_normalize :mobile_phone, default_country_code: "BG", add_plus: false - mount_uploader :picture, PictureUploader + has_one_attached :picture accepts_nested_attributes_for :user diff --git a/app/models/user.rb b/app/models/user.rb index 950a5f1..b8a1cde 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,7 +38,7 @@ class User < ActiveRecord::Base def build_personal_profile(conference, params = {}) if personal_profiles.last.present? new_personal_profile = personal_profiles.last.try(:dup) - CopyCarrierwaveFile::CopyFileService.new(personal_profiles.last, new_personal_profile, :picture).set_file + new_personal_profile.picture.attach(personal_profiles.last.picture.blob) else new_personal_profile = personal_profiles.build end diff --git a/app/models/volunteer.rb b/app/models/volunteer.rb index e3a4ac1..e45bdd5 100644 --- a/app/models/volunteer.rb +++ b/app/models/volunteer.rb @@ -3,7 +3,7 @@ class Volunteer < ActiveRecord::Base TSHIRT_CUTS = [:unisex, :female] FOOD_PREFERENCES = [:none, :vegetarian, :vegan] - attachment :picture, type: :image + has_one_attached :picture validates :name, :language, :tshirt_size, :tshirt_cut, :food_preferences, presence: true validates :tshirt_size, inclusion: {in: TSHIRT_SIZES.map(&:to_s)} diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb deleted file mode 100644 index 707e7e1..0000000 --- a/app/uploaders/picture_uploader.rb +++ /dev/null @@ -1,53 +0,0 @@ -class PictureUploader < CarrierWave::Uploader::Base - # Include RMagick or MiniMagick support: - # include CarrierWave::RMagick - include CarrierWave::MiniMagick - - # Choose what kind of storage to use for this uploader: - storage :file - # storage :fog - - # 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 - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" - end - - # Provide a default URL as a default if there hasn't been a file uploaded: - def default_url - ActionController::Base.helpers.asset_path("fallback/profile_picture/" + [version_name, "default.png"].compact.join("_")) - end - - # Process files as they are uploaded: - # process :scale => [200, 300] - # - # def scale(width, height) - # # do something - # end - - # Create different versions of your uploaded files: - - version :medium do - process resize_to_fit: [171, 180] - end - - version :thumb do - process resize_to_fit: [50, 50] - end - - version :schedule do - process resize_to_fill: [100, 100] - 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 png] - end - - # Override the filename of the uploaded files: - # Avoid using model.id or version_name here, see uploader/store.rb for details. - # def filename - # "something.jpg" if original_filename - # end -end diff --git a/app/views/management/events/_speaker.slim b/app/views/management/events/_speaker.slim index 534947f..1806d41 100644 --- a/app/views/management/events/_speaker.slim +++ b/app/views/management/events/_speaker.slim @@ -5,7 +5,7 @@ .panel.panel-default - if personal_profile.present? .panel-image - = image_tag personal_profile.picture.url + = image_tag personal_profile.picture .panel-body .media .media-body diff --git a/app/views/management/personal_profiles/_form.html.slim b/app/views/management/personal_profiles/_form.html.slim index 3b4ed3d..3ce9b77 100644 --- a/app/views/management/personal_profiles/_form.html.slim +++ b/app/views/management/personal_profiles/_form.html.slim @@ -10,9 +10,9 @@ .panel-body .row .col-lg-12 - - if f.object.picture.present? + - if f.object.picture.attached? .col-sm-offset-3.col-sm-9 - = image_tag f.object.picture.medium.url, class: 'img-thumbnail' + = image_tag f.object.picture.variant(resize_to_limit: [150, 150]), class: 'img-thumbnail' = f.input :picture, wrapper: :horizontal_file_input diff --git a/app/views/management/personal_profiles/index.html.slim b/app/views/management/personal_profiles/index.html.slim index 5d24ff9..289f2a5 100644 --- a/app/views/management/personal_profiles/index.html.slim +++ b/app/views/management/personal_profiles/index.html.slim @@ -27,10 +27,9 @@ .media .media-left - if profile.present? - = image_tag(profile.picture.thumb.url) + = image_tag(profile.picture.variant(resize_to_fill: [50, 50])) - else - = image_tag(PictureUploader.new.thumb.url) - + = image_tag('avatar-placeholder') .media-body h4.media-heading - if profile.try(:name).present? diff --git a/app/views/management/personal_profiles/show.html.slim b/app/views/management/personal_profiles/show.html.slim index d5cd02a..763aca0 100644 --- a/app/views/management/personal_profiles/show.html.slim +++ b/app/views/management/personal_profiles/show.html.slim @@ -9,7 +9,7 @@ .col-sm-5.col-md-4 .panel.panel-default .panel-image - = image_tag @profile.picture.url + = image_tag @profile.picture .panel-body .media .media-body diff --git a/app/views/management/volunteers/_form.html.slim b/app/views/management/volunteers/_form.html.slim index 8b4522b..50ace56 100644 --- a/app/views/management/volunteers/_form.html.slim +++ b/app/views/management/volunteers/_form.html.slim @@ -5,9 +5,9 @@ .col-lg-12 - if f.object.picture.present? .col-sm-offset-3.col-sm-9 - = attachment_image_tag(@volunteer, :picture, :fill, 150, 150) if @volunteer.picture.present? + = @volunteer.picture.variant(resize_to_limit: [150, 150]) if @volunteer.picture.attached? - = f.input :picture, as: :attachment, wrapper: :horizontal_file_input, direct: true + = f.input :picture, as: :file, wrapper: :horizontal_file_input, direct: true = f.input :name, autofocus: true = f.input :email diff --git a/app/views/management/volunteers/index.html.slim b/app/views/management/volunteers/index.html.slim index 614c984..6d62c57 100644 --- a/app/views/management/volunteers/index.html.slim +++ b/app/views/management/volunteers/index.html.slim @@ -41,9 +41,9 @@ .media .media-left - if volunteer.picture.present? - = attachment_image_tag(volunteer, :picture, :fill, 50, 50) + = image_tag volunteer.picture.variant(resize_to_limit: [50, 50]) - else - = image_tag(PictureUploader.new.thumb.url) + = image_tag('avatar-placeholder.png') .media-body h4.media-heading = volunteer.name diff --git a/app/views/management/volunteers/show.html.slim b/app/views/management/volunteers/show.html.slim index 75def37..0004289 100644 --- a/app/views/management/volunteers/show.html.slim +++ b/app/views/management/volunteers/show.html.slim @@ -10,17 +10,18 @@ .panel-body .media .media-left.hidden-sm.hidden-xs - - if @volunteer.picture.present? - = attachment_image_tag(@volunteer, :picture, :fill, 150, 150) + - if @volunteer.picture.attached? + = image_tag @volunteer.picture.variant(resize_to_limit: [150, 150]) - else - = image_tag(PictureUploader.new.medium.url) + = image_tag('avatar-placeholder.png') .media-body .text-center.visible-sm.visible-xs - - if @volunteer.picture.present? - = attachment_image_tag(@volunteer, :picture, :fill, 150, 150) + - if @volunteer.picture.attached? + = image_tag @volunteer.picture.variant(resize_to_limit: [150, 150]) - else - = image_tag(PictureUploader.new.medium.url) + = image_tag('avatar-placeholder.png') + h4.media-heading = @volunteer.name hr diff --git a/app/views/volunteer_mailer/team_notification.text.erb b/app/views/volunteer_mailer/team_notification.text.erb index 5d0583f..8ede00f 100644 --- a/app/views/volunteer_mailer/team_notification.text.erb +++ b/app/views/volunteer_mailer/team_notification.text.erb @@ -4,7 +4,6 @@ Екипи: <%= @volunteer.volunteer_teams.map(&:name).join(', ') %> -Снимка: <%= attachment_url(@volunteer, :picture, host: "https://#{@volunteer.conference.host_name}/") %> Език: <%= @volunteer.language %> Телефон: <%= @volunteer.phone %> Размер на тениска: <%= @volunteer.tshirt_size %> diff --git a/config/application.rb b/config/application.rb index 708a86f..6b83897 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ Bundler.require(*Rails.groups) module Clarion class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.2 + config.load_defaults 7.1 # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. diff --git a/config/environments/development.rb b/config/environments/development.rb index 393ccc5..cd5c6d8 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -76,4 +76,6 @@ Rails.application.configure do # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true + + config.hosts << "dev.openfest.org:3000" end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 0227f33..953b2c4 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -9,7 +9,7 @@ Rails.application.config.assets.version = "1.0" Rails.application.config.assets.paths << "lib/initfest/assets/images" Rails.application.config.assets.paths << "lib/initfest/assets/javascripts" Rails.application.config.assets.paths << "lib/initfest/assets/stylesheets" -Rails.application.config.assets.precompile << /\.(?:png|jpg|jpeg|gif)\z/ +#Rails.application.config.assets.precompile << /\.(?:png|jpg|jpeg|gif)\z/ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets diff --git a/config/locales/management.bg.yml b/config/locales/management.bg.yml index 584b7a7..04025c8 100644 --- a/config/locales/management.bg.yml +++ b/config/locales/management.bg.yml @@ -34,6 +34,8 @@ bg: no_comments_received: Все още няма коментари. private_email: Личен e-mail events: + update: + event_successfully_updated: Събитието беше обновено успешно show: average_grade: Средна оценка total_feedback_grades: diff --git a/db/migrate/20240219234146_create_active_storage_tables.active_storage.rb b/db/migrate/20240219234146_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..e4706aa --- /dev/null +++ b/db/migrate/20240219234146_create_active_storage_tables.active_storage.rb @@ -0,0 +1,57 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[7.0] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :active_storage_blobs, id: primary_key_type do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :key ], unique: true + end + + create_table :active_storage_attachments, id: primary_key_type do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + t.references :blob, null: false, type: foreign_key_type + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + + create_table :active_storage_variant_records, id: primary_key_type do |t| + t.belongs_to :blob, null: false, index: false, type: foreign_key_type + t.string :variation_digest, null: false + + t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 3af6183..ac28fd9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,8 +5,10 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first -User.create(email: "foo@example.com", - password: "123qweASD", - password_confirmation: "123qweASD", - confirmed_at: Time.current, - admin: true) +User.create( + email: "foo@example.com", + password: "123qweASD", + password_confirmation: "123qweASD", + confirmed_at: Time.current, + admin: true +) diff --git a/lib/initfest/assets/javascripts/initfest/application.js b/lib/initfest/assets/javascripts/initfest/application.js index 646c5ab..787b237 100644 --- a/lib/initfest/assets/javascripts/initfest/application.js +++ b/lib/initfest/assets/javascripts/initfest/application.js @@ -13,3 +13,4 @@ //= require jquery //= require jquery_ujs //= require_tree . +//= require activestorage diff --git a/lib/initfest/views/public/personal_profiles/_form.slim b/lib/initfest/views/public/personal_profiles/_form.slim index 52b1992..8b42d6b 100644 --- a/lib/initfest/views/public/personal_profiles/_form.slim +++ b/lib/initfest/views/public/personal_profiles/_form.slim @@ -3,10 +3,9 @@ .form-inputs .input - = image_tag(@profile.picture.medium.url) if @profile.picture? - = f.input :picture, as: :file, required: true, wrapper: false - - = f.hidden_field :picture_cache, class: 'image_preview', wrapper: false + = image_tag(@profile.picture.variant(resize_to_limit: [150, 150])) if @profile.picture.attached? + = f.hidden_field :picture, value: @profile.picture.signed_id if @profile.picture.attached? + = f.input :picture, as: :file, required: true, wrapper: false, input_html: {direct_upload: true} = f.input :first_name, autofocus: true = f.input :last_name = f.input :public_email diff --git a/lib/initfest/views/public/volunteers/_form.slim b/lib/initfest/views/public/volunteers/_form.slim index 8104d33..af6c94a 100644 --- a/lib/initfest/views/public/volunteers/_form.slim +++ b/lib/initfest/views/public/volunteers/_form.slim @@ -5,8 +5,8 @@ .form-inputs .input - = attachment_image_tag(@volunteer, :picture, :fill, 150, 150) if @volunteer.picture.present? - = f.input :picture, as: :attachment, direct: true, wrapper: false + = image_tag @volunteer.picture.variant(resize_to_limit: [150, 150]) if @volunteer.picture.attached? + = f.input :picture, as: :file, direct: true, wrapper: false = f.input :name, autofocus: true = f.input :email = f.input :phone, input_html: {value: @volunteer.phone.try(:phony_formatted, format: :international)} diff --git a/public/uploads/.keep b/public/uploads/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/public/uploads/tmp/.keep b/public/uploads/tmp/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/models/volunteership_spec.rb b/spec/models/volunteership_spec.rb deleted file mode 100644 index 6238804..0000000 --- a/spec/models/volunteership_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "rails_helper" - -RSpec.describe Volunteership, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index b3febab..281ca62 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -103,7 +103,7 @@ module FeatureHelpers attach_file PersonalProfile.human_attribute_name(:picture), Rails.root.join("spec", "support", "picture.jpg") fill_in PersonalProfile.human_attribute_name(:first_name), with: "Foo" fill_in PersonalProfile.human_attribute_name(:last_name), with: "Bar" - fill_in PersonalProfile.human_attribute_name(:mobile_phone), with: "+359666666" + fill_in PersonalProfile.human_attribute_name(:mobile_phone), with: "+359883123456" fill_in PersonalProfile.human_attribute_name(:biography), with: "Lorem" click_on I18n.t("helpers.submit.create", model: PersonalProfile.model_name.human) diff --git a/spec/support/matchers/has_errors_on.rb b/spec/support/matchers/has_errors_on.rb index fc00050..a4f9693 100644 --- a/spec/support/matchers/has_errors_on.rb +++ b/spec/support/matchers/has_errors_on.rb @@ -1,6 +1,6 @@ RSpec::Matchers.define :have_error_on do |expected| match do |actual| expect(actual).to_not be_valid - expect(actual.errors.keys).to include expected + expect(actual.errors).to have_key expected end end