-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from paperclip to activestorage
- Loading branch information
Showing
20 changed files
with
149 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and | ||
* the trix-editor content (whether displayed or under editing). Feel free to incorporate this | ||
* inclusion directly in any other asset bundle and remove this file. | ||
* | ||
*= require trix | ||
*/ | ||
|
||
/* | ||
* We need to override trix.css’s image gallery styles to accommodate the | ||
* <action-text-attachment> element we wrap around attachments. Otherwise, | ||
* images in galleries will be squished by the max-width: 33%; rule. | ||
*/ | ||
.trix-content .attachment-gallery > action-text-attachment, | ||
.trix-content .attachment-gallery > .attachment { | ||
flex: 1 0 33%; | ||
padding: 0 0.5em; | ||
max-width: 33%; | ||
} | ||
|
||
.trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment, | ||
.trix-content .attachment-gallery.attachment-gallery--2 > .attachment, .trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment, | ||
.trix-content .attachment-gallery.attachment-gallery--4 > .attachment { | ||
flex-basis: 50%; | ||
max-width: 50%; | ||
} | ||
|
||
.trix-content action-text-attachment .attachment { | ||
padding: 0 !important; | ||
max-width: 100% !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ApplicationMailbox < ActionMailbox::Base | ||
# routing /something/i => :somewhere | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>"> | ||
<% if blob.representable? %> | ||
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> | ||
<% end %> | ||
<figcaption class="attachment__caption"> | ||
<% if caption = blob.try(:caption) %> | ||
<%= caption %> | ||
<% else %> | ||
<span class="attachment__name"><%= blob.filename %></span> | ||
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span> | ||
<% end %> | ||
</figcaption> | ||
</figure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="trix-content"> | ||
<%= yield -%> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
- location_picture_xrefs.each do |lpx| | ||
- if lpx.photo? | ||
= link_to image_tag(lpx.photo.url(:medium)), lpx.photo.url(:large), :class => "location_thumb location_picture_xref_#{lpx.id}", :"data-lightbox" => "location_thumb" | ||
- if lpx.photo.attached? | ||
= link_to image_tag(lpx.photo.variant(resize_to_limit: [100,100])), lpx.photo.variant(resize_to_limit: [800,800]), :class => "location_thumb location_picture_xref_#{lpx.id}", :"data-lightbox" => "location_thumb" | ||
= render :partial => 'location_picture_xrefs/remove_picture', :locals => {:lpx => lpx} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
db/migrate/20250129200229_create_action_text_tables.action_text.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This migration comes from action_text (originally 20180528164100) | ||
class CreateActionTextTables < ActiveRecord::Migration[6.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 :action_text_rich_texts, id: primary_key_type do |t| | ||
t.string :name, null: false | ||
t.text :body, size: :long | ||
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type | ||
|
||
t.timestamps | ||
|
||
t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true | ||
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 |
20 changes: 20 additions & 0 deletions
20
db/migrate/20250129200703_create_action_mailbox_tables.action_mailbox.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This migration comes from action_mailbox (originally 20180917164000) | ||
class CreateActionMailboxTables < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :action_mailbox_inbound_emails, id: primary_key_type do |t| | ||
t.integer :status, default: 0, null: false | ||
t.string :message_id, null: false | ||
t.string :message_checksum, null: false | ||
|
||
t.timestamps | ||
|
||
t.index [ :message_id, :message_checksum ], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true | ||
end | ||
end | ||
|
||
private | ||
def primary_key_type | ||
config = Rails.configuration.generators | ||
config.options[config.orm][:primary_key_type] || :primary_key | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace :location_picture_xrefs do | ||
task migrate_to_active_storage: :environment do | ||
LocationPictureXref.where.not(photo_file_name: nil).find_each do |lpx| | ||
# This step helps us catch any attachments we might have uploaded that | ||
# don't have an explicit file extension in the filename | ||
image_original = lpx.photo_file_name | ||
# ext = File.extname(image) | ||
# image_original = CGI.unescape(image.gsub(ext, "_original#{ext}")) | ||
|
||
# this url pattern can be changed to reflect whatever service you use | ||
lpx_url = "https://s3.amazonaws.com/pbm-images/location_picture_xref/photo/#{lpx.id}/original/#{image_original}" | ||
lpx.photo.attach(io: OpenURI.open_uri(lpx_url), | ||
filename: lpx.photo_file_name, | ||
content_type: lpx.photo_content_type) | ||
rescue OpenURI::HTTPError, URI::InvalidURIError => e | ||
puts "bad image path #{lpx_url}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# one: | ||
# record: name_of_fixture (ClassOfFixture) | ||
# name: content | ||
# body: <p>In a <i>million</i> stars!</p> |