Class: Shared::Collection::TablePresenter

Inherits:
Presenter
  • Object
show all
Defined in:
app/presenters/shared/collection/table_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(subject, options = {}) ⇒ TablePresenter

Returns a new instance of TablePresenter.



2
3
4
5
6
7
8
9
10
# File 'app/presenters/shared/collection/table_presenter.rb', line 2

def initialize(subject, options = {})
  super(subject, options)
  
  set_default_options(
    {  
      current_parent: parent, show_title: true, append_new_link: true, show_actions: true
    }
  )
end

Instance Method Details

#actionsObject



16
17
18
19
20
# File 'app/presenters/shared/collection/table_presenter.rb', line 16

def actions
  return (:td, '') unless show_actions
  
   :td, render('shared/resource/actions', type: type, resource: resource)
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/presenters/shared/collection/table_presenter.rb', line 22

def new_link(options = {})
  return '' unless append_new_link

  path = if current_parent
    send(
      "new_#{root_model_class_name(current_parent).tableize.singularize}_#{type.gsub('.', '_').singularize}_path", 
      current_parent, options
    )
  else
    send("new_#{type.gsub('.', '_').singularize}_path", options)
  end
  
  link_to t("#{type}.new.title"), path
end

#set_options(options) ⇒ Object



12
13
14
# File 'app/presenters/shared/collection/table_presenter.rb', line 12

def set_options(options)
  @options.merge!(options)
end