Skip to content


Updated Formtastic example to work with Formtastic 2 #46

wants to merge 3 commits into from

1 participant



Formtastic 2 deprecated the enum_input helper described in the readme.

Here's an updated version of the code.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 17 additions and 1 deletion.
  1. +17 −1 README.rdoc
18 README.rdoc
@@ -502,7 +502,23 @@ Second, do not forget to add the +enum_attr+ macro to the generated model and mi
=== Formtastic integration
-You can display the select input in a Formtastic form with a little monkey patching. First, extend Formtastic with an initializer:
+You can make Formtastic generate a select with the enum values filled in automatically.
+For Formtastic 2, define a custom input class:
+ require 'formtastic'
+ class EnumInput < Formtastic::Inputs::SelectInput
+ def raw_collection
+ @raw_collection ||= collection_from_options || collection_from_enum
+ end
+ def collection_from_enum
+ @object.enums(method.to_sym).try(:select_options) || []
+ end
+ end
+For Formtastic 1, define a custom helper:
require 'formtastic'
Something went wrong with that request. Please try again.