Migrate Paperclip → has_local_attached in Image, News, Quote models

This commit is contained in:
BenClaw
2026-06-08 21:46:44 +02:00
parent f3369b8fa9
commit da5db36b4c
5 changed files with 11 additions and 38 deletions
-1
View File
@@ -26,7 +26,6 @@ gem 'simply_couch' , github: 'bterkuile/simply_couch', branch: 'master'
gem 'devise' gem 'devise'
gem 'devise_simply_couch', github: 'bterkuile/devise_simply_couch', branch: 'master' gem 'devise_simply_couch', github: 'bterkuile/devise_simply_couch', branch: 'master'
gem 'slim-rails' gem 'slim-rails'
gem 'paperclip', ['>= 3.4', '!= 4.3.0']
gem 'email_validator' gem 'email_validator'
# Declare any dependencies that are still in development here instead of in # Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or # your gemspec. These might include edge Rails or gems from your path or
+5 -14
View File
@@ -1,20 +1,11 @@
module Cmtool module Cmtool
class Image class Image
include SimplyCouch::Model include SimplyCouch::Model
include Paperclip::Glue # Paperclip → has_local_attached migration
# TODO: Replace Paperclip with SimplyCouch::HasAttachment has_local_attached :file,
# 1. Change `include Paperclip::Glue` to `include SimplyCouch::HasAttachment` styles: { page: '728x10000>', medium: '354x1000>', thumb: '160x1250>' },
# 2. Replace `has_attached_file :file, styles: {...}` with `has_attachment :file, styles: {...}` content_type: %w[image/jpeg image/gif image/png]
# 3. Replace `validates_attachment` with standard Rails validations validates :file_file_name, presence: true
property :file_file_name
property :file_content_type
property :file_file_size, type: Integer
property :file_updated_at, type: Time
has_attached_file :file, styles: { page: '728x10000>', medium: "354x1000>", thumb: "160x1250>" },
path: ":rails_root/public/system/:attachment/:id/:style.:extension",
url: "/system/:attachment/:id/:style.:extension"
validates_attachment :file, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
belongs_to :directory belongs_to :directory
+3 -11
View File
@@ -1,22 +1,14 @@
module Cmtool module Cmtool
class News class News
include SimplyCouch::Model include SimplyCouch::Model
include Paperclip::Glue
# TODO: Replace Paperclip with SimplyCouch::HasAttachment
# 1. Change `include Paperclip::Glue` to `include SimplyCouch::HasAttachment`
# 2. Replace `has_attached_file :image, styles: {...}` with `has_attachment :image, styles: {...}`
property :title property :title
property :active, type: :boolean, default: true property :active, type: :boolean, default: true
property :date, type: Date property :date, type: Date
property :body property :body
property :image_file_name # Paperclip → has_local_attached migration
property :image_content_type has_local_attached :image,
property :image_file_size, type: Integer styles: { medium: '500x500>', thumb: '250x250>' }
property :image_updated_at, type: Time
has_attached_file :image, styles: { :medium => "500x500>", :thumb => "250x250>" }
has_and_belongs_to_many :keywords, storing_keys: true has_and_belongs_to_many :keywords, storing_keys: true
validates :title, presence: true validates :title, presence: true
validates :date, presence: true validates :date, presence: true
+3 -11
View File
@@ -1,11 +1,6 @@
module Cmtool module Cmtool
class Quote class Quote
include SimplyCouch::Model include SimplyCouch::Model
include Paperclip::Glue
# TODO: Replace Paperclip with SimplyCouch::HasAttachment
# 1. Change `include Paperclip::Glue` to `include SimplyCouch::HasAttachment`
# 2. Replace `has_attached_file :image, styles: {...}` with `has_attachment :image, styles: {...}`
property :owner property :owner
property :function property :function
property :state property :state
@@ -13,12 +8,9 @@ module Cmtool
property :active, type: :boolean, default: true property :active, type: :boolean, default: true
property :locale property :locale
property :image_file_name # Paperclip → has_local_attached migration
property :image_content_type has_local_attached :image,
property :image_file_size, type: Integer styles: { medium: '300x1000>', thumb: '137x1250>' }
property :image_updated_at, type: Time
has_attached_file :image, styles: {medium: "300x1000>", thumb: "137x1250>" }
view :for_sidebar_view, key: [:state, :created_at], conditions: %{doc['active']} view :for_sidebar_view, key: [:state, :created_at], conditions: %{doc['active']}
STATES = %w[page sidebar] STATES = %w[page sidebar]
-1
View File
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "slim-rails", ">= 0" s.add_runtime_dependency "slim-rails", ">= 0"
# s.add_runtime_dependency "tinymce-rails", ">= 0" # s.add_runtime_dependency "tinymce-rails", ">= 0"
s.add_runtime_dependency "jquery-rails", ">= 0" s.add_runtime_dependency "jquery-rails", ">= 0"
s.add_runtime_dependency "paperclip", ">= 0"
s.add_runtime_dependency "foundation-rails", ">= 0" s.add_runtime_dependency "foundation-rails", ">= 0"
s.add_runtime_dependency "ace-rails-ap", ">= 0" s.add_runtime_dependency "ace-rails-ap", ">= 0"
s.add_runtime_dependency "font-awesome-rails", ">= 0" s.add_runtime_dependency "font-awesome-rails", ">= 0"