23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/helpers/manage/resource_helper.rb', line 23
def action_link(scope, link_data)
value = nil
if link_data.is_a? (Hash)
relation = link_data.keys.first
entity = Fields::Reader.field_value(scope, relation)
unless entity.present?
return ''
end
if link_data[relation][:label_field].present?
value = field_value(scope, link_data[relation][:label_field])
elsif link_data[relation][:label].present?
value = link_data[relation][:label]
end
path = entity.class.name.dasherize.pluralize.downcase
return link_to value, [scope.public_send(relation)]
end
if link_data.is_a? (Symbol) or link_data.is_a?(String)
relation = link_data.to_s
if scope.class.reflect_on_association(link_data.to_sym).options[:class_name].present?
rel_name = scope.class.reflect_on_association(link_data.to_sym).options[:class_name]
relation = rel_name.downcase.dasherize.pluralize
end
if scope.class.reflect_on_association(link_data.to_sym).options[:as].present?
key = scope.class.reflect_on_association(link_data.to_sym).options[:as].to_s + '_id'
else
key = scope.class.name.downcase.dasherize + '_id'
end
return "<a href=\"#{relation}?f%5B#{key}%5D=#{scope.id}\">#{resource_class.human_attribute_name(link_data.to_s)}</a>".html_safe
end
unless value
raise 'Unsupported link data'
end
end
|