Helper class for formating HTML tables used for the browse/search results pages.
Attributes
action | [R] |
The |
columns | [R] |
The data columns for the current table |
model | [R] |
The |
objs | [R] |
An array of objects to show in the table |
request | [R] |
The |
type | [R] |
The action type for the current table |
Public Class methods
new(action, objs)
[show source]
# File lib/autoforme/table.rb 24 def initialize(action, objs) 25 @action = action 26 @request = action.request 27 @model = action.model 28 @type = action.normalized_type 29 @columns = model.columns_for(type, request) 30 @objs = objs 31 end
Public Instance methods
to_s()
Return an HTML string for the table.
[show source]
# File lib/autoforme/table.rb 38 def to_s 39 html = String.new 40 html << "<table id=\"autoforme_table\" class=\"#{model.table_class_for(type, request)}\">" 41 42 html << "<thead><tr>" 43 columns.each do |column| 44 html << "<th>#{h action.column_label_for(type, request, model, column)}</th>" 45 end 46 html << "<th>Show</th>" if show = model.supported_action?(:show, request) 47 html << "<th>Edit</th>" if edit = model.supported_action?(:edit, request) 48 html << "<th>Delete</th>" if delete = model.supported_action?(:delete, request) 49 html << "</tr></thead>" 50 51 html << "<tbody>" 52 objs.each do |obj| 53 html << "<tr>" 54 columns.each do |column| 55 unless val = model.show_html_for(obj, column, type, request) 56 val = model.column_value(type, request, obj, column) 57 val = val.to_s('F') if defined?(BigDecimal) && val.is_a?(BigDecimal) 58 val = h(val) 59 end 60 html << "<td>#{val}</td>" 61 end 62 html << "<td><a href=\"#{action.url_for("show/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-info\">Show</a></td>" if show 63 html << "<td><a href=\"#{action.url_for("edit/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-primary\">Edit</a></td>" if edit 64 html << "<td><a href=\"#{action.url_for("delete/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-danger\">Delete</a></td>" if delete 65 html << "</tr>" 66 end 67 html << "</tbody></table>" 68 html 69 end