Class: Edgarj::Drawer::ColumnInfo::BelongsTo

Inherits:
Normal
  • Object
show all
Defined in:
app/helpers/edgarj/drawer/base.rb

Overview

auto-generated column-info for ‘belongs_to’ column

parent model is assumed to have ‘name’ method

Instance Method Summary collapse

Methods inherited from Normal

#label, #name, #sort_key, #tag_options, #type

Methods inherited from Base

#field, #label, #name, #sort_key, #tag_options, #type

Constructor Details

#initialize(model, name, parent_model, belongs_to_link) ⇒ BelongsTo

Returns a new instance of BelongsTo.



180
181
182
183
184
# File 'app/helpers/edgarj/drawer/base.rb', line 180

def initialize(model, name, parent_model, belongs_to_link)
  super(model, name)
  @parent_model     = parent_model
  @belongs_to_link  = belongs_to_link
end

Instance Method Details

#column_header_label(vc, page_info, options) ⇒ Object

column header for ‘belongs_to’ column prints label without any sort action unlike Normal-class behavior.



188
189
190
# File 'app/helpers/edgarj/drawer/base.rb', line 188

def column_header_label(vc, page_info, options)
  vc.draw_belongs_to_label_sub(@model, name, @parent_model)
end

#column_value(rec, drawer) ⇒ Object



192
193
194
195
196
197
198
199
# File 'app/helpers/edgarj/drawer/base.rb', line 192

def column_value(rec, drawer)
  @parent_rec = rec.belongs_to_AR(@ar_column_info)
  if @belongs_to_link
    drawer.vc.link_to(@parent_rec.name, drawer.popup_path(self), remote: true)
  else
    @parent_rec ? @parent_rec.name : ''
  end
end