diff --git a/app/models/user.rb b/app/models/user.rb index 002e2bcb..2dbfea11 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) } diff --git a/script/migrate_user_attachments_to_new_path.rb b/script/migrate_user_attachments_to_new_path.rb new file mode 100644 index 00000000..bd31cc8b --- /dev/null +++ b/script/migrate_user_attachments_to_new_path.rb @@ -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