Module: RailsDb::TablesHelper

Defined in:
app/helpers/rails_db/tables_helper.rb

Instance Method Summary collapse

Instance Method Details

#delete_row_path(table, record) ⇒ Object



33
34
35
36
37
38
39
# File 'app/helpers/rails_db/tables_helper.rb', line 33

def delete_row_path(table, record)
  table_destroy_path(table,
    pk_id: record[table.primary_key],
    page: params[:page],
    sort_column: params[:sort_column],
    sort_order: params[:sort_order])
end

#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({ action: :data, sort_column: column, sort_order: sort_order }), {remote: true, class: css_class }
end

#table_pagination_pathObject



41
42
43
44
# File 'app/helpers/rails_db/tables_helper.rb', line 41

def table_pagination_path
  params.delete(:pk_id)
  params.merge({action: :data})
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