Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate user attachments to new path #355

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class User < ActiveRecord::Base
has_many :notifications

has_attached_file :image, styles: { :thumb => "150x150#", :medium => "250x250#" },
path: ":attachment/:style/:basename.:extension"
path: ":attachment/:style/:basename_:updated_at.:extension",
validate_media_type: false # TODO comment out for prod
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/

default_scope { order(created_at: :desc) }
Expand Down
9 changes: 9 additions & 0 deletions script/migrate_user_attachments_to_new_path.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class FakeUser < User
has_attached_file :image, styles: { :thumb => "150x150#", :medium => "250x250#" },
path: ":attachment/:style/:basename.:extension"
end

FakeUser.find_each do |fake_user|
User.find(fake_user.id).update(image: fake_user.image)
# fake_user.image.destroy
end
Loading