Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nbrew/442539 to your computer and use it in GitHub Desktop.
Save nbrew/442539 to your computer and use it in GitHub Desktop.
class AddSmallAndLargeThumbnailSizes < ActiveRecord::Migration
# added inline RefinerySetting class
class RefinerySetting < ActiveRecord::Base
serialize :value # stores into YAML format
def self.find_or_set(name, the_value, options={})
# if the database is not up to date yet then it won't know about scoping..
if self.column_names.include?('scoping')
options = {:scoping => nil}.merge(options)
find_or_create_by_name_and_scoping(:name => name.to_s, :value => the_value, :scoping => options[:scoping]).value
else
find_or_create_by_name(:name => name.to_s, :value => the_value).value
end
end
def value=(new_value)
# must convert to string if true or false supplied otherwise it becomes 0 or 1, unfortunately.
new_value = new_value.to_s if ["trueclass","falseclass"].include?(new_value.class.to_s.downcase)
self[:value] = new_value
end
end
def self.up
image_thumbnails = RefinerySetting.find_or_set(:image_thumbnails, {})
image_thumbnails = image_thumbnails.dup.update({
:small => '110x110>',
:medium => '225x255>',
:large => '450x450>'
})
setting = RefinerySetting.find_by_name('image_thumbnails')
setting.value = image_thumbnails
setting.save!
end
def self.down
# don't really need to reverse it, it's not destructive if you run it multiple times.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment