Module: ActiveRecordView::Helper
Instance Method Summary
collapse
Methods included from RenderArv
#render, #render_arv
#link_to_destroy, #link_to_edit, #link_to_list, #link_to_new, #link_to_save, #link_to_show
#write_exception, #write_exception_logger
#active_record_name_for, #demodulized_class_name, #dom_class, #dom_id, #partial_path, #plural_class_name, #singular_class_name
Instance Method Details
#active_record_error(err, record_or_name, format, options) ⇒ Object
67
68
69
70
|
# File 'lib/active_record_view/helper.rb', line 67
def active_record_error(err, record_or_name, format, options)
write_exception(err)
'???'
end
|
52
53
54
55
56
57
58
59
|
# File 'lib/active_record_view/helper.rb', line 52
def active_record_form(record_or_name, format, options = {})
record_name = active_record_name_for(record_or_name)
record = options[:record] || active_record_for(record_or_name)
engine = find_active_record_view_engine(record.class, format, "edit_")
engine.edit(record, format, self, record_name)
rescue Exception => err
active_record_error(err, record_or_name, format, options)
end
|
#active_record_value(record_or_name, format, options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/active_record_view/helper.rb', line 41
def active_record_value(record_or_name, format, options = {})
record = active_record_for(record_or_name)
engine = find_active_record_view_engine(record.class, format)
engine.show(record, format, self)
rescue NameError => err
write_exception(err)
record[format]
rescue Exception => err
active_record_error(err, record_or_name, format, options)
end
|
#collection_tbody_for(*args) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/active_record_view/helper.rb', line 30
def collection_tbody_for(*args)
html = collection_tr_for(*args)
if html.blank?
return nil
else
content_tag(:tbody, html)
end
end
|
#collection_tr_for(*args) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/active_record_view/helper.rb', line 7
def collection_tr_for(*args)
options = args.optionize :records, :fields
return nil if options[:records].blank?
if options[:fields].blank?
record = options[:records].first
record.is_a?(ActiveRecord::Base) or
raise TypeError, "expect ActiveRecord, but got #{record.class}"
options[:fields] = record.class.content_columns.map(&:name)
end
options[:records].map do |record|
style = list_row_class(record) if respond_to? :list_row_class
content_tag :tr,
options[:fields].map{|name|
html = active_record_value(record, name, :singular_name => options[:singular_name])
content_tag :td, html, :class=>name
}.join,
:class => [style, dom_class(record), options[:class] || options[:singular_name]].compact.join(' '),
:id => dom_id(record, options[:prefix])
end.join
end
|
#find_active_record_view_engine(klass, column, prefix = nil) ⇒ Object
61
62
63
64
65
|
# File 'lib/active_record_view/helper.rb', line 61
def find_active_record_view_engine(klass, column, prefix = nil)
caching_key = [klass, column, prefix]
@cached_arv_engines ||= {}
@cached_arv_engines[caching_key] ||= active_record_view_engine_for(klass, column, prefix)
end
|