Module: Models::SearchableView

Overview

Shared behavior for read-only search views backed by database views.

Formerly BaseViewForSearch. Mixed into View* models (e.g.
ViewCustomer) to expose CRM link helpers, column presence checks, and
sales-rep filter scopes that are callable via Ransack.

See Also:

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

Relative CRM path to the underlying resource this view row represents.

Returns:

  • (String)

    path such as "/customers/123"

See Also:

  • main_resource_table


29
30
31
# File 'app/concerns/models/searchable_view.rb', line 29

def crm_link
  "/#{self.class.main_resource_table}/#{id}"
end

Subtitle shown under the record title in CRM search results.

Returns:

  • (String)

    defaults to the CRM link; views may override



36
37
38
# File 'app/concerns/models/searchable_view.rb', line 36

def crm_link_subtitle
  crm_link
end

#has_columns?(*columns) ⇒ Boolean

Checks that every named column has a non-blank value on this row.

Parameters:

  • columns (Array<Symbol, String>)

    column names to check

Returns:

  • (Boolean)

    true when all columns are present and non-blank



44
45
46
# File 'app/concerns/models/searchable_view.rb', line 44

def has_columns?(*columns)
  columns.map(&:to_sym).all? { |column| !try(:send, column).nil? && try(:send, column).to_s.present? }
end

#readonly?Boolean

Search views are backed by database views and are never writable.

Returns:

  • (Boolean)

    always true



51
52
53
# File 'app/concerns/models/searchable_view.rb', line 51

def readonly?
  true
end