app/models/blog_post.rb
# For images that haven't been uploaded yet, they get a random image id
# with 'upload' infront of it.  We replace those with their new image
# id
For images that haven't been uploaded yet, they get a random image id
with 'upload' infront of it.  We replace those with their new image
id
For images that haven ' t been uploaded yet they get a random image id with ' upload ' infront of it . We replace those with their new image id
def replace_blog_image_tags
		@resaving = true
		self.body.gsub!(/[{]blog_image:upload[0-9]+:[a-zA-Z]+[}]/) do |image_tag|
			random_id, size = image_tag.scan(/upload([0-9]+)[:]([a-zA-Z]+)/).flatten
			new_id = random_id
			matching_image = self.blog_images.reject {|bi| !bi.random_id || bi.random_id != random_id }.first
			if matching_image
				new_id = matching_image.id
			end
			"{blog_image:#{new_id}:#{size}}"
		end
		self.save
		@resaving = false
		return true
	end
def replace_blog_image_tags @resaving = true self . body . gsub! ( / [{]blog_image:upload[0-9]+:[a-zA-Z]+[}] / ) do | image_tag | random_id , size = image_tag . scan ( / upload([0-9]+)[:]([a-zA-Z]+) / ) . flatten new_id = random_id matching_image = self . blog_images . reject { | bi | ! bi . random_id || bi . random_id != random_id } . first if matching_image new_id = matching_image . id end "{blog_image:#{new_id}:#{size}}" end self . save @resaving = false return true end
For images that haven't been uploaded yet, they get a random image id
with 'upload' infront of it.
For images that haven ' t been uploaded yet they get a random image id with ' upload ' infront of it .