Module: RailsDb::TablesHelper
- Defined in:
- app/helpers/rails_db/tables_helper.rb
Instance Method Summary collapse
- #format_value(column, value) ⇒ Object
- #select_top_from_table(table) ⇒ Object
- #sortable(column, title = nil) ⇒ Object
- #titleize_column(column, title = nil) ⇒ Object
Instance Method Details
#format_value(column, value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/rails_db/tables_helper.rb', line 4 def format_value(column, value) return value # TODO here return nil unless value case column.type when :datetime I18n.l(DateTime.parse(value), format: :long) when :date I18n.l(Date.parse(value), format: :long) else value end end |
#select_top_from_table(table) ⇒ Object
29 30 31 |
# File 'app/helpers/rails_db/tables_helper.rb', line 29 def select_top_from_table(table) link_to raw("#{fa_icon('database')} SQL Query"), rails_db.sql_path(sql: "select * from #{table} limit 10") end |
#sortable(column, title = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'app/helpers/rails_db/tables_helper.rb', line 18 def sortable(column, title = nil) title = titleize_column(column, title) css_class = (column == params[:sort_column]) ? "current #{params[:sort_order]}" : nil sort_order = (column == params[:sort_column] && params[:sort_order] == 'asc') ? 'desc' : 'asc' link_to title, params.merge({ sort_column: column, sort_order: sort_order }), {remote: true, class: css_class } end |
#titleize_column(column, title = nil) ⇒ Object
25 26 27 |
# File 'app/helpers/rails_db/tables_helper.rb', line 25 def titleize_column(column, title = nil) column end |