Created
July 24, 2008 00:55
form helper to display tags from acts_as_taggable_on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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