Module: RailsDb::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#db_hint_optionsObject



47
48
49
50
51
52
53
# File 'app/helpers/rails_db/application_helper.rb', line 47

def db_hint_options
  result = {}
  RailsDb::Database.accessible_tables.each do |table_name|
    result[table_name] = RailsDb::Table.new(table_name).columns.inject({}) {|res, e| res[e.name] = nil; res }
  end
  result
end

#fa_icon(icon_name) ⇒ Object



43
44
45
# File 'app/helpers/rails_db/application_helper.rb', line 43

def fa_icon(icon_name)
  %{<i class="fa fa-#{icon_name}"></i>}.html_safe
end


7
8
9
10
11
12
13
14
# File 'app/helpers/rails_db/application_helper.rb', line 7

def link_to_add_fields(name, f, type)
  new_object = f.object.send "build_#{type}"
  id = "new_#{type}"
  fields = f.send("#{type}_fields", new_object, child_index: id) do |builder|
    render(type.to_s + "_fields", f: builder)
  end
  link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
end

#main_content_classesObject



24
25
26
27
28
29
30
# File 'app/helpers/rails_db/application_helper.rb', line 24

def main_content_classes
  if show_sidebar?
    'large-9 push-3 columns collapsed'
  else
    'large-12 push-0 columns expanded'
  end
end

#params_to_hash(p) ⇒ Object



55
56
57
58
59
60
61
# File 'app/helpers/rails_db/application_helper.rb', line 55

def params_to_hash(p)
  if p.respond_to?(:to_unsafe_h)
    p.to_unsafe_h
  else
    p
  end
end

#rails_db_tablesObject



3
4
5
# File 'app/helpers/rails_db/application_helper.rb', line 3

def rails_db_tables
  RailsDb::Database.accessible_tables
end

#show_sidebar?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'app/helpers/rails_db/application_helper.rb', line 32

def show_sidebar?
  return true if controller_name == 'dashboard' && action_name == 'index'
  cookies['sidebar_visible'] == 'true'
end


16
17
18
19
20
21
22
# File 'app/helpers/rails_db/application_helper.rb', line 16

def sidebar_classes
  if show_sidebar?
    'large-3 large-pull-9 columns'
  else
    'large-3 large-pull-9 columns hide'
  end
end

#title(str) ⇒ Object



37
38
39
40
41
# File 'app/helpers/rails_db/application_helper.rb', line 37

def title(str)
  content_for :title do
    raw("#{str}"[0].upcase + "#{str}"[1..-1])
  end
end