Module: ActsAsLinkable::ActionViewExtensions

Defined in:
lib/acts_as_linkable/acts_as_linkable.rb

Instance Method Summary collapse

Instance Method Details

#href(item) ⇒ Object



39
40
41
# File 'lib/acts_as_linkable/acts_as_linkable.rb', line 39

def href(item)
  url_for (item.parent ? [item.parent, item] : item)
end


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/acts_as_linkable/acts_as_linkable.rb', line 9

def link(obj, options={}, html_options={})
  raise "I can't link to nil." unless obj
  if (obj.class == Array) || (obj.class == ActiveRecord::Relation)
    obj.map{|v| link(v)}.to_sentence
  else
    link_attr = obj.link_attr
    link_attr[:partial] = "#{obj.class.name.tableize}/link" if link_attr.empty?
    if link_attr[:partial]
      obj_name = (link_attr[:object_name] ||= obj.class.name.underscore).to_s.to_sym
      (render :partial => link_attr[:partial], :locals => {obj_name => obj}).strip
    else
      name = obj.send(obj.link_attr[:name])
      obj.link_attr.except(:name).each do |key, val|
        html_options[key] ||= ((val.class==Symbol) ? obj.send(val) : val)
      end
      link_obj = options.empty? ? obj : self.send("#{obj.class.name.tableize}_path", obj, options.except(:remote))

      link_obj = [link_obj.send(link_obj.parent), link_obj] if link_obj.parent
      link_to name, link_obj, html_options
    end
  end
end

#tag_list(item, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/acts_as_linkable/acts_as_linkable.rb', line 31

def tag_list(item, options={})
  tags = item.send(:tag_list_on, options[:on] || :tags)
  url = href(item)
  tags.map! do |t|
    link_to t, "#{url}?tag=#{t}"
  end
  tags.join(", ")
end