Created
June 17, 2010 18:38
-
-
Save nbrew/442539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment