在轨中对字符串类型的键使用转义序列

时间:2018-08-07 12:55:17

标签: ruby-on-rails ruby

您好,我正在尝试将一个哈希值合并到一个算法中,该算法最终应使用特定ID更新我的一个模型中的列。 在我的调试器中,一切似乎都很好,我正在获取正确的数据。我想到的唯一错误是我的哈希具有字符串类型的键。是否有办法向这些字符串添加转义序列,以免它们破坏我的代码?

这是哈希

if Rails.env.development?
        loan_sectors = { "Agriculture/Farming" => [8], "Bars/Public Houses" => [1,2,8,9,6], "B&Bs" => [], "Beauty" => [], "Bio Pharma Engineering" => [],
                "Cafes" => [], "Car Sales Industry" => [], "Construction - Commercial" => [127], "Construction - Residential" => [],
                "Consultancy" => [], "Distribution Services" => [],  "Education" => [] , "Engineering"  => [], "Entertainment" => [],
                "Environmental and CleanTech Products and Services" => [] , "Financial Services" => [] , "Garages—Car Repair etc." => [],
                "Health" => [], "Hotels" => [] , "Legal services" => [], "Marketing Services" => [], "Media Services" => [] , "Motor Industry" => [],
                "Manufacturing"  => [],  "Pharmaceuticals" => [], "Recruitment Services" => [], "Restaurants" => [], "Retail Services" => [],
                "Telecoms Industry" => [], "Tourism" => [], "Transport - Import" => [], "Transport - Export" => [],
                "Transport - Internal" => [],"Wholesale" => []}

        loan_sectors.each do |k, v|
          byebug
          sector = LoanSector.where(name: k).first
          v.each do |cid|
            Campaign.find(cid).loan.update_column(:loan_sector_id, sector.id)
          end
        end
      end

0 个答案:

没有答案