app/models/loop_item_type.rb
def loop_item_name_with the_name, default_language, loop_source
    #l_item_name = item_types[row_as_a[i][0].to_s].loop_item_names.find_by_item_name(row_as_a[i][1].to_s)
    the_name_db_safe = the_name
    begin
      the_l_item_name_field = self.loop_item_name_fields.find_by_item_name(the_name)
    rescue
      the_name_db_safe = the_name.force_encoding("ISO-8859-1").encode("UTF-8").to_s
      the_l_item_name_field = self.loop_item_name_fields.find_by_item_name(the_name_db_safe)
    end

    l_item_name = the_l_item_name_field.present? ? the_l_item_name_field.loop_item_name : nil

    return l_item_name if l_item_name

    l_item_name = LoopItemName.new()
    l_item_name.loop_item_type_id = self.id
    l_item_name.loop_source_id = loop_source.id

    l_item_name.transaction do
      l_item_name.save!

      l_item_name_field = l_item_name.loop_item_name_fields.build(
        item_name: the_name_db_safe,
        language: default_language,
        is_default_language: true
      )

      l_item_name_field.save!
    end

    l_item_name
  end
#Fetches the LoopItemName that has a a loop_item_name_field with item_name as 'the_name'
#Passes in the default language to specify if a new LoopItemNameField needs to be created
Fetches the LoopItemName that has a a loop_item_name_field with item_name as 'the_name'
Passes in the default language to specify if a new LoopItemNameField needs to be created
Fetches the LoopItemName that has a a loop_item_name_field with item_name as ' the_name ' Passes in the default language to specify if a new LoopItemNameField needs to be created
def loop_item_name_with the_name, default_language, loop_source
    the_name_db_safe = the_name
    begin
      the_l_item_name_field = self.loop_item_name_fields.find_by_item_name(the_name)
    rescue
      the_name_db_safe = the_name.force_encoding("ISO-8859-1").encode("UTF-8").to_s
      the_l_item_name_field = self.loop_item_name_fields.find_by_item_name(the_name_db_safe)
    end
    l_item_name = the_l_item_name_field.present? ? the_l_item_name_field.loop_item_name : nil
    return l_item_name if l_item_name
    l_item_name = LoopItemName.new()
    l_item_name.loop_item_type_id = self.id
    l_item_name.loop_source_id = loop_source.id
    l_item_name.transaction do
      l_item_name.save!
      l_item_name_field = l_item_name.loop_item_name_fields.build(
        item_name: the_name_db_safe,
        language: default_language,
        is_default_language: true
      )
      l_item_name_field.save!
    end
    l_item_name
  end
def loop_item_name_with the_name , default_language , loop_source the_name_db_safe = the_name begin the_l_item_name_field = self . loop_item_name_fields . find_by_item_name ( the_name ) rescue the_name_db_safe = the_name . force_encoding ( "ISO-8859-1" ) . encode ( "UTF-8" ) . to_s the_l_item_name_field = self . loop_item_name_fields . find_by_item_name ( the_name_db_safe ) end l_item_name = the_l_item_name_field . present? ? the_l_item_name_field . loop_item_name : nil return l_item_name if l_item_name l_item_name = LoopItemName . new ( ) l_item_name . loop_item_type_id = self . id l_item_name . loop_source_id = loop_source . id l_item_name . transaction do l_item_name . save! l_item_name_field = l_item_name . loop_item_name_fields . build ( item_name : the_name_db_safe , language : default_language , is_default_language : true ) l_item_name_field . save! end l_item_name end
Fetches the LoopItemName that has a a loop_item_name_field with item_name as 'the_name'
Passes in the default language to specify if a new LoopItemNameField needs to be created
Fetches the LoopItemName that has a a loop_item_name_field with item_name as ' the_name ' Passes in the default language to specify if a new LoopItemNameField needs to be created
#l_item_name = item_types[row_as_a[i][0].to_s].loop_item_names.find_by_item_name(row_as_a[i][1].to_s)
the_name
default_language
loop_source