def draw_belongs_to_field(f, popup_path, col_name, model = f.object.class)
      col   = model.columns.detect{|c| c.name == col_name.to_s}
      return "no column found" if !col

      parent_model = model.belongs_to_AR(col)
      return "parent_model is nil" if !parent_model

      parent_obj  = f.object.belongs_to_AR(col)
      popup_field = Edgarj::PopupHelper::PopupField.new_builder(
          f.object_name, col_name)
      default_label = '[' + draw_belongs_to_label_sub(model, col.name, parent_model) + ']'
      label = content_tag(:span,
          parent_obj ? parent_obj.name : default_label.html_safe,
          id: popup_field.label_target)
      link_tag = Settings.edgarj.belongs_to.link_tag.html_safe
      if parent_obj
        if Settings.edgarj.belongs_to.popup_on == 'field'
          link_to(
              label + link_tag,
              popup_path,
              remote: true)
        else
          link_to(label,
              # TODO: Hardcoded 'master' prefix should be fixed
              controller: url_prefix + parent_obj.class.name.underscore.pluralize,
              action:     'show',
              id:         parent_obj,
              topic_path: 'add')
        end
      else
        if Settings.edgarj.belongs_to.popup_on == 'field'
          link_to(
              label + link_tag,
              popup_path,
              remote: true)
        else
          label
        end
      end +
      draw_belongs_to_clear_link(f, col.name, popup_field,
          parent_obj && parent_obj.name,
          default_label)
    end
def draw_belongs_to_field(f, popup_path, col_name, model = f.object.class)
      col   = model.columns.detect{|c| c.name == col_name.to_s}
      return "no column found" if !col

      parent_model = model.belongs_to_AR(col)
      return "parent_model is nil" if !parent_model

      parent_obj  = f.object.belongs_to_AR(col)
      popup_field = Edgarj::PopupHelper::PopupField.new_builder(
          f.object_name, col_name)
      default_label = '[' + draw_belongs_to_label_sub(model, col.name, parent_model) + ']'
      label = content_tag(:span,
          parent_obj ? parent_obj.name : default_label.html_safe,
          id: popup_field.label_target)
      link_tag = Settings.edgarj.belongs_to.link_tag.html_safe
      if parent_obj
        if Settings.edgarj.belongs_to.popup_on == 'field'
          link_to(
              label + link_tag,
              popup_path,
              remote: true)
        else
          link_to(label,
              # TODO: Hardcoded 'master' prefix should be fixed
              controller: url_prefix + parent_obj.class.name.underscore.pluralize,
              action:     'show',
              id:         parent_obj,
              topic_path: 'add')
        end
      else
        if Settings.edgarj.belongs_to.popup_on == 'field'
          link_to(
              label + link_tag,
              popup_path,
              remote: true)
        else
          label
        end
      end +
      draw_belongs_to_clear_link(f, col.name, popup_field,
          parent_obj && parent_obj.name,
          default_label)
    end
draw 'belongs_to' popup data-entry field

 This is usually used with draw_belongs_to_label().

 @param f          [FormBuilder] FormBuilder object
 @param popup_path [String]      popup path(url)
 @param col_name   [String]      'belongs_to' column name
 @param model      [AR]          data model class