ref: master
db/migrate/20110706171330_fix_misunderstood_script_filename.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#FIXME Don't know why, but this xss_terminate and sanitize_tag_list calls here # from the migration fall on a loop and breaks the migration. Both them are # related to alias_method_chain, probably there is a problem with this kind of # alias on the migration level. class Article < ApplicationRecord def sanitize_tag_list end end module XssTerminate module InstanceMethods def sanitize_fields_with_white_list end end end #FIXME This after save calls the environment methods 'blocks' and # 'portal_community'. Both acts as not defined don't know why. class ArticleSweeper < ActiveRecord::Observer def after_save(article) end end class FixMisunderstoodScriptFilename < ActiveRecord::Migration def self.up Image.all.select { |i| !i.thumbnail? && File.extname(i.filename) == '.txt'}.map do |image| image.thumbnails.destroy_all image.filename = fixed_name(image) image.save! image.create_thumbnails end UploadedFile.all.select { |u| u.image? && File.extname(u.filename) == '.txt' }.map do |uploaded_file| uploaded_file.thumbnails.destroy_all uploaded_file.filename = fixed_name(uploaded_file) uploaded_file.save! uploaded_file.create_thumbnails end Thumbnail.all.select { |u| u.image? && File.extname(u.filename) == '.txt' }.map do |thumbnail| thumbnail.filename = fixed_name(thumbnail) thumbnail.save! end end def self.down say "WARNING: cannot undo this migration" end class << self def fixed_name(file) file.filename.gsub('.txt', '') end end end |