Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Formtastic example to work with Formtastic 2 #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down