Module: UsersHelper

Defined in:
app/helpers/users_helper.rb

Overview

Helper module for working with users in your application.

Class Method Summary collapse

Class Method Details

.get_inspector_name(property_id) ⇒ String

Get the name of the inspector assigned to a specific property.

Parameters:

  • property_id (Integer)

    The ID of the property to find the inspector for.

Returns:

  • (String)

    The full name of the inspector assigned to the property, or an empty string if not found.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/users_helper.rb', line 9

def self.get_inspector_name(property_id)
  #users = User.where(user_type: 'inspector')
  users = User.where('user_type IN (?)', ['inspector'])
  users.each do |user|
    if user.properties.present?

      property_ids = user.properties['property_ids'].to_s.split(',')
      property_ids = property_ids.map(&:to_i)

      if property_ids.present?
        if property_ids.include? property_id
          return user.first_name + " " + user.last_name
        end
      end
    end
  end
  ''
end