Skip to content

Instantly share code, notes, and snippets.

@rubyonrailsworks
Created January 18, 2013 07:12
Show Gist options
  • Save rubyonrailsworks/4562892 to your computer and use it in GitHub Desktop.
Save rubyonrailsworks/4562892 to your computer and use it in GitHub Desktop.
导入作品数据
def self.load_old_data
OldDesign.all.each do |old|
user = User.find_by_old_id(old.user_id)
next unless user
design = Design.create(user_id: user.id, title: old.title, content: old.title, view_count: old.view_count,
style: old.style, recommended: old.recommended, tag_list: old.tags.gsub(',', ','))
p design
OldDesignFile.where(:old_design_id => old.id).all.each do |file|
image = DesignImage.new
image.user_id = user.id
image.imageable = design
image.is_cover = file.is_cover
handle = open(file.src) rescue nil
next unless image.file
handle.class.class_eval { attr_accessor :original_filename, :content_type }
handle.original_filename = file.src.split("/").last
image.file = handle
image.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment