Skip to content

Instantly share code, notes, and snippets.

@olivoil
Forked from ches/tags_input.rb
Created January 20, 2011 19:20
Show Gist options
  • Save olivoil/788431 to your computer and use it in GitHub Desktop.
Save olivoil/788431 to your computer and use it in GitHub Desktop.
# 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