Module: ActsAsLinkable::ActionViewExtensions

Defined in:
lib/acts_as_linkable_core.rb

Instance Method Summary collapse

Instance Method Details



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

def link(obj)
  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
    p = obj.link_attr
    p[:partial] = "#{obj.class.name.tableize}/link" if p.empty?
    unless p[:partial].nil?
      obj_name = (p[:object_name] ||= obj.class.name.underscore).to_s.to_sym
      (render :partial => p[:partial], :locals => {obj_name => obj}).strip
    else
      opts = {}
      link_attr = obj.link_attr
      link_attr.each do |key, val|
        link_attr[key] = obj.send(val) if val.class == Symbol
      end
      opts[:title] = link_attr[:title] if link_attr.has_key?(:title)
      link_to link_attr[:name], obj, opts
    end
  end
end