Module: Tramway::Admin::RecordsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/tramway/admin/records_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_tab(tab, index) ⇒ Object



62
63
64
65
# File 'app/helpers/tramway/admin/records_helper.rb', line 62

def active_tab(tab, index)
  return :active if params[:scope].nil? && index == 0
  return :active if params[:search].nil? && params[:scope].to_s == tab.to_s
end

#admin_index_path_of_model(model_class, tab = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'app/helpers/tramway/admin/records_helper.rb', line 44

def admin_index_path_of_model(model_class, tab = nil)
  if tab
    records_path model: model_class, scope: tab
  else
    records_path model: model_class
  end
end

#current_model_record_path(*args, **options) ⇒ Object

FIXME replace to module



4
5
6
# File 'app/helpers/tramway/admin/records_helper.rb', line 4

def current_model_record_path(*args, **options)
  record_path args, options.merge(model: params[:model])
end

#current_model_records_path(*args, **options) ⇒ Object



16
17
18
# File 'app/helpers/tramway/admin/records_helper.rb', line 16

def current_model_records_path(*args, **options)
  records_path args, options.merge(model: params[:model])
end

#decorator_classObject



24
25
26
# File 'app/helpers/tramway/admin/records_helper.rb', line 24

def decorator_class
  "#{model_class}Decorator".constantize
end

#edit_current_model_record_path(*args, **options) ⇒ Object



8
9
10
# File 'app/helpers/tramway/admin/records_helper.rb', line 8

def edit_current_model_record_path(*args, **options)
  edit_record_path args, options.merge(model: params[:model])
end

#get_collection(model_class) ⇒ Object



28
29
30
# File 'app/helpers/tramway/admin/records_helper.rb', line 28

def get_collection(model_class)
  decorator_class.collections
end

#model_classObject



20
21
22
# File 'app/helpers/tramway/admin/records_helper.rb', line 20

def model_class
  params[:model].constantize
end

#new_current_model_record_path(*args, **options) ⇒ Object



12
13
14
# File 'app/helpers/tramway/admin/records_helper.rb', line 12

def new_current_model_record_path(*args, **options)
  new_record_path args, options.merge(model: params[:model])
end

#search_tab_title(count) ⇒ Object



36
37
38
# File 'app/helpers/tramway/admin/records_helper.rb', line 36

def search_tab_title(count)
  "#{t("helpers.found")} / #{count}"
end

#searchable_model?(model_class) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/helpers/tramway/admin/records_helper.rb', line 40

def searchable_model?(model_class)
  model_class.methods.include?(:search) || model_class.methods.include?(:search_everywhere)
end

#tab_title(model_class, tab, count, state_method = :state) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'app/helpers/tramway/admin/records_helper.rb', line 52

def tab_title(model_class, tab, count, state_method = :state)
  model = model_class.name.underscore
  name = if t("default.collections.#{tab}").include?('<span')
           t("collections.#{model}.#{tab}").pluralize(:ru)
         else 
           t("default.collections.#{tab}")
         end
  "#{name} / #{count}"
end

#to_path(constant) ⇒ Object



32
33
34
# File 'app/helpers/tramway/admin/records_helper.rb', line 32

def to_path(constant)
  constant.name.underscore.gsub '/', '_'
end