Created
April 22, 2013 22:19
-
-
Save gogogarrett/5439062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %label Search | |
| %input#filter | |
| %hr | |
| %table.footable{"data-filter" => "#filter"} | |
| %thead | |
| %tr | |
| - if block | |
| %th | |
| - headers.each_with_index do |header, index| | |
| %th | |
| = header.to_s.humanize | |
| - if actions | |
| %th | |
| Actions | |
| %tbody | |
| - collection.each do |obj| | |
| %tr[obj] | |
| - if block | |
| %td | |
| = block.call(obj) | |
| - headers.each_with_index do |header, index| | |
| %td | |
| = cell_value(obj, header, index) | |
| - if actions | |
| %td | |
| =raw action_links_for(obj).join(" ") | |
| %hr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| = form_tag url: school_class_add_multiple_path, method: :post do | |
| = table_grid_for @students, headers: [:first_name, :last_name, :email] do |student| | |
| - check_box_tag "student_ids[]", student.id | |
| %br | |
| = submit_tag "Add Students", class: 'btn btn-primary' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %h1 All students | |
| = table_grid_for(@students, headers: [:first_name, :last_name, :email, :grade]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module TableGridHelper | |
| def table_grid_for(collection, options={}, &block) | |
| collection = collection.to_a.flatten | |
| headers = options.fetch(:headers) | |
| include_action = options.fetch(:actions, true) | |
| render partial: "shared/grid", locals: { | |
| collection: collection, | |
| headers: headers, | |
| actions: include_action, | |
| block: block | |
| } | |
| end | |
| def cell_value(obj, header, index) | |
| index.zero? ? link_to(obj.send(header), obj) : obj.send(header) | |
| end | |
| def action_links_for(obj) | |
| [ | |
| link_to("Edit", [:edit, obj], class: 'btn btn-primary'), | |
| link_to("Delete", obj, method: :delete, class: 'btn btn-primary') | |
| ] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment