Module: MyTags::ApplicationHelper

Defined in:
app/helpers/my_tags/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#all_tags(opts = {}) ⇒ Object

Show all tags



17
18
19
20
21
# File 'app/helpers/my_tags/application_helper.rb', line 17

def all_tags(opts = {})
   :div, class: opts.fetch(:html_class, nil) do
    tag_list_with_link(Tag.uniq(:name))
  end.html_safe
end

#tag_list(obj, opts = {}) ⇒ Object

Show all object tags



10
11
12
13
14
# File 'app/helpers/my_tags/application_helper.rb', line 10

def tag_list(obj, opts = {})
   :div, class: opts.fetch(:html_class, nil) do
    tag_list_with_link(obj.tags)
  end.html_safe
end


23
24
25
26
27
28
29
# File 'app/helpers/my_tags/application_helper.rb', line 23

def tag_list_with_link(tag_list)
  tag_list.map do |tag|
     :a, href: tag_path(tag.name) do
      tag.name.capitalize
    end
  end.join(', ').html_safe
end

#tags_field_tag(object) ⇒ Object



4
5
6
7
# File 'app/helpers/my_tags/application_helper.rb', line 4

def tags_field_tag(object)
  html_value = object.tags.blank? ? nil : (object.tags.map(&:name).join(', ') + ', ')
  text_field_tag "#{object.class.to_s.downcase}[tag_list]", html_value, placeholder: 'Tags', class: 'my_taggable', 'data-tags_list_path' => my_tags_list_path
end