README.md in has_enum-0.9.1 vs README.md in has_enum-0.9.2

- old
+ new

@@ -14,53 +14,80 @@ $ bundle install ## Usage ### Models Here's example model: - class TestModel < ActiveRecord::Base - has_enum :category, %w( stuff things misc ) - has_enum :color , %w( red green blue ) , :scopes => true - has_enum :size , %w( small medium large ) , :query_methods => false - has_enum :status , [:pending, :failed, :done] - end + +```ruby +class TestModel < ActiveRecord::Base + has_enum :category, %w( stuff things misc ) + has_enum :color , %w( red green blue ) , :scopes => true + has_enum :size , %w( small medium large ) , :query_methods => false + has_enum :status , [:pending, :failed, :done] +end +``` + Query methods are available by default. For example, query methods for color enum this methods will be available: + color_green? color_red? color_blue? + If you set *:scopes => true* these scopes will be available: - color_green - color_red - color_blue + +```ruby + color_green + color_red + color_blue +``` + See [sample usage in specs](https://github.com/openteam/has_enum/blob/master/spec/has_enum_spec.rb). ### Views + +```ruby radio_button_enum(object_name, method, options = {}) select_enum(object_name, method, options = {}) +``` + #### Usage with Formtastic (Monkeypatch) + If you are using another gems that inherited from formtastic the most simple method will be to add this code in your *config/initializers/formtastic.rb*: + +```ruby class Formtastic::SemanticFormBuilder def enum_input(method, options = {}) value = @object.send(method) additional_params = {:as => :select, :collection => @object.class.values_for_select_tag(method)} self.input(method, options.merge(additional_params)).gsub(/class="select/, 'class="enum') end end +``` + Or if you sure you don't use any the proper method is to inherit from it: + +```ruby class CustomBuilder < Formtastic::SemanticFormBuilder def enum_input(method, options = {}) value = @object.send(method) additional_params = {:as => :select, :collection => @object.class.values_for_select_tag(method)} self.input(method, options.merge(additional_params)).gsub(/class="select/, 'class="enum') end end +``` + And uncomment +```ruby Formtastic::SemanticFormHelper.builder = CustomBuilder +``` ## Running Tests Run the tests + rake spec + View specs are still failing. I'm working on it. ## Contributing to has_enum * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet