Created
August 31, 2011 01:32
-
-
Save tsmango/1182604 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Category < ActiveRecord::Base | |
| configure do | |
| option :sort do | |
| default 'alphabetical' | |
| restrict 'alphabetical', 'manual' | |
| end | |
| option :limit do | |
| format 'fixnum' | |
| end | |
| option :price_filter do | |
| format 'float' | |
| modifiers 'eq', 'lt', 'gt', 'lte', 'gte' | |
| multiple true | |
| end | |
| end | |
| end |
This file contains hidden or 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
| >> category = Category.create(:name => 'Vinyl Records') | |
| => #<Category id: 1, name: "Vinyl Records", created_at: "2011-08-03 15:46:11", updated_at: "2011-08-03 15:46:11"> | |
| ?> category.settings | |
| => #<ActiveConfiguration::SettingManager:0x10e7d1950 @configurable=#<Category id: 1, name: "Vinyl Records", created_at: "2011-08-03 15:46:11", updated_at: "2011-08-03 15:46:11">> | |
| ?> category.settings[:sort] | |
| => {:value=>"alphabetical", :modifier=>nil} | |
| ?> category.settings[:sort][:value] | |
| => "alphabetical" | |
| ?> category.settings[:sort][:value] = 'manual' | |
| => "manual" | |
| ?> category.settings[:price_filter] | |
| => [] | |
| ?> category.settings[:price_filter] = [{:modifier => 'gt', :value => 10.00}, {:modifier => 'lte', :value => 25.00}] | |
| => [{:value=>10.0, :modifier=>"gt"}, {:value=>25.0, :modifier=>"lte"}] | |
| ?> category.save | |
| => true | |
| ?> category.settings[:sort][:value] | |
| => "manual" | |
| ?> category.settings[:price_filter] | |
| => [{:value=>10.0, :modifier=>"gt"}, {:value=>25.0, :modifier=>"lte"}] |
This file contains hidden or 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
| rails g active_configuration:install |
This file contains hidden or 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
| gem 'active_configuration' |
This file contains hidden or 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
| rake db:migrate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment