Module: RailsDb::TablesHelper

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

Instance Method Summary collapse

Instance Method Details

#column_is_checked?(table_name, column_name) ⇒ Boolean

Returns:

  • (Boolean)


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

def column_is_checked?(table_name, column_name)
  if cookies["Table: #{table_name}"].present?
    !cookies["Table: #{table_name}"].split(',').include?(column_name)
  else
    true
  end
end

#delete_row_path(table, record) ⇒ Object



26
27
28
29
30
31
# File 'app/helpers/rails_db/tables_helper.rb', line 26

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

#display_style_column(table_name, column_name) ⇒ Object



46
47
48
# File 'app/helpers/rails_db/tables_helper.rb', line 46

def display_style_column(table_name, column_name)
  column_is_checked?(table_name, column_name) ? 'display' : 'display:none'
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

#search_form_classObject



50
51
52
# File 'app/helpers/rails_db/tables_helper.rb', line 50

def search_form_class
  params[:q].present? ? '' : 'hide'
end

#select_top_from_table(table) ⇒ Object



22
23
24
# File 'app/helpers/rails_db/tables_helper.rb', line 22

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

#table_pagination_pathObject



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

def table_pagination_path
  params.delete(:pk_id)
  params_to_hash params.merge({action: :data})
end

#titleize_column(column, title = nil) ⇒ Object



18
19
20
# File 'app/helpers/rails_db/tables_helper.rb', line 18

def titleize_column(column, title = nil)
  column
end