Module: Manage::ResourceHelper

Defined in:
app/helpers/manage/resource_helper.rb

Instance Method Summary collapse

Instance Method Details



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

#attributesObject



11
12
13
# File 'app/helpers/manage/resource_helper.rb', line 11

def attributes
  resource_class.attribute_names - %w(id created_at updated_at)
end

#edit_fieldsObject



7
8
9
# File 'app/helpers/manage/resource_helper.rb', line 7

def edit_fields
  list_edit_fields
end

#field_title(resource_class, field_data) ⇒ Object



19
20
21
# File 'app/helpers/manage/resource_helper.rb', line 19

def field_title(resource_class, field_data)
  Fields::Reader.field_title(resource_class, field_data)
end

#field_value(scope, field_data) ⇒ Object



15
16
17
# File 'app/helpers/manage/resource_helper.rb', line 15

def field_value(scope, field_data)
  Fields::Reader.field_value(scope, field_data).to_s
end

#index_fieldsObject



3
4
5
# File 'app/helpers/manage/resource_helper.rb', line 3

def index_fields
  list_index_fields
end