ruby-on-rails - 在rails中对字符串类型的键使用转义序列
问题描述
您好,我有一个哈希值,我正在尝试将其合并到一个算法中,该算法最终应该更新我的一个模型中具有特定 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
解决方案
推荐阅读
- java - 双击.jar时Java获取当前工作目录
- python - IndexError:使用beautifulsoup 抓取广告时列出的索引超出范围
- sql - 如何从 ip2location ip 数据库中选择多个 ip 信息?
- flutter - 在 performLayout() 期间抛出了以下断言 RenderCustomMultiChildLayoutBox 对象被赋予了无限大小
- excel - 是否有一个 Excel 函数将应用于每 4 行并将被重置或重新初始化
- bash - 当我通过将脚本放在 /usr/local/bin 中全局使用脚本时,Bash 脚本标志参数不起作用
- jenkins - Azure Devops 存储库上的多分支管道选项?
- python-3.x - 我需要锁定我的标题,以便没有人可以编辑这些列,但我想使用 xlsxwriter 启用自动过滤器
- javascript - 有没有办法将 SVG 元素放在具有绝对位置的 HTML div 上方?
- python - 如何从python中的for循环逐列将数据写入csv?