Tag: rails upgrade

序列化哈希,日期为YAML rails

TL; DR :Rails 5.1,Ruby 2.4.0将包含时间对象的哈希序列化,并在时间的字符串表示周围加上引号。 这些引用不存在于Rails 2.3,Ruby 1.8.7中并且打破了我的应用程序; 我怎么摆脱他们? 背景和细节 我正在将应用程序从Rails 2.3,Ruby 1.8.7升级到Rails 5.1,Ruby 2.4.0。 我有一个ReportService类,它有一个report_params hash的report_params构造函数参数。 创建这些对象后,此哈希将以YAML格式序列化。 class ReportService < ApplicationRecord # irrelevant AR associations omitted serialize :report_params serialize :output_urls end 用户提交一个表单,其中包含他们想要运行的报表的详细信息,包括使用Time.parse()解析的字符串,该字符串将作为构造函数参数传递; 所以代码(以程序forms删除不相关的细节,省略了许多无关的东西)看起来像 offset = customer.timezone.nil? ? ‘+0000’ : customer.timezone.formatted_offset(:time => start_date) params[:date_from] = Time.parse(“#{start_date} #{params[:hour_from]}:{params[:min_from]} #{offset}”).utc.strftime(‘%Y-%m-%d %H:%M:%S’) report_args = {… report_params: { … […]