Skip to content

Instantly share code, notes, and snippets.

@oliyoung
Created July 24, 2008 00:55
Show Gist options
  • Save oliyoung/1975 to your computer and use it in GitHub Desktop.
Save oliyoung/1975 to your computer and use it in GitHub Desktop.
form helper to display tags from acts_as_taggable_on
class ActionView::Helpers::FormBuilder
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper
def tag_list(method, options={})
return false unless options[:tags]
links = options[:tags].map do |tag|
link_to_function( tag.to_s, "toggle_tag('#{tag}', '#{@object.class.to_s.downcase}_#{method.to_s.pluralize.downcase}')", :class => ["tag", (@object.send(method).map(&:name).include?(tag.to_s) ? "selected" : "")].compact.join(" "), :id => tag )
end
content = links.join(" ") + tag(:br, :style=>"clear:both")
hidden_field(method, :value=>@object.send(method.to_s).join(", ")) +
content_tag(:div, content, :class=>"tags", :id=>"#{@object.class.to_s.downcase}_#{method.to_s.pluralize.downcase}_tags")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment