Module: SimpleTableFor::Helpers
- Defined in:
- lib/simple_table_for/helpers.rb
Instance Method Summary collapse
-
#field(content, options = {}) ⇒ Object
Creates a table field See table_for for details.
-
#table_for(collection, headers, options = {}) ⇒ Object
Creates a table Usage: <%= table_for @posts, %w[Title Text Date Comments\ count -] do |post| %> <%= field post.title %> <%= field post.text %> <%= field post.date %> <%= field post.comments.count %> <%= field link_to(‘View’, post) %> <% end %>.
Instance Method Details
#field(content, options = {}) ⇒ Object
Creates a table field See table_for for details
5 6 7 |
# File 'lib/simple_table_for/helpers.rb', line 5 def field(content, = {}) content_tag :td, content, end |
#table_for(collection, headers, options = {}) ⇒ Object
Creates a table Usage:
<%= table_for @posts, %w[Title Text Date Comments\ count -] do |post| %>
<%= field post.title %>
<%= field post.text %>
<%= field post.date %>
<%= field post.comments.count %>
<%= field link_to('View', post) %>
<% end %>
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simple_table_for/helpers.rb', line 18 def table_for(collection, headers, = {}) = Defaults.get.merge content_tag :table, do concat (content_tag :thead do content_tag :tr do headers.map do |header| concat(content_tag :th, header) end end end) concat (content_tag :tbody do collection.map do |obj| concat (content_tag :tr do capture{ yield obj } end) end end) end end |