Skip to content

Instantly share code, notes, and snippets.

@ches
Created January 16, 2011 18:08
Show Gist options
  • Save ches/781997 to your computer and use it in GitHub Desktop.
Save ches/781997 to your computer and use it in GitHub Desktop.
simple_form input builder for use with my mongoid_taggable fork
# Example simple_form input builder to render tags from an Array field,
# for use with my fork of mongoid_taggable:
#
# https://github.com/ches/mongoid_taggable
#
# Once you've configured your app to load this, use it in forms thusly:
#
# <%= f.input :tags, :as => :tags %>
#
module SimpleForm
module Inputs
class TagsInput < StringInput
protected
def html_options_for(namespace, extra)
formatted_tags = object.send("#{attribute_name}").
try(:join, "#{object.send(:tags_separator)} ")
super.merge(:value => formatted_tags)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment