【问题标题】:Delayed Job adding special characters to rails object延迟作业向 rails 对象添加特殊字符
【发布时间】:2013-09-18 16:42:15
【问题描述】:

我将一个延迟作业任务排队,该任务将对象 json 表示形式保存到 s3。该对象的属性之一是版权信息,其中包括版权符号。版权符号在数据库中显示得很好,如果我在控制器中“放置 object.copyright_info”,但是当我在延迟的作业文件中“放置 object.copyright_info”时,它添加了特殊字符。

Controller

def create_json
  puts @object.copyright_info #copy right symbol appears correctly - "Copyright ©"
  Delayed::Job.enqueue SaveS3Json.new(@object)
end

保存json文件:

class SaveS3Json < Struct.new(:object)
  # encoding: utf-8

  def perform
    puts object.copyright_info #outputs "Copyright ©"
    # calls object.to_json and writes json file to s3
 end

我正在使用 ruby​​-1.9.2-p32 和 Postgresql 在 Heroku 上运行。当我在本地执行相同的任务时,似乎没有添加特殊字符。

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails heroku character-encoding delayed-job


    【解决方案1】:

    我通过简单地将对象 ID 而不是完整对象传递给 Struct.new() 类解决了我的问题。在 SaveS3Json 类中获得 ID 后,我只需执行普通 Active Record .find(id) 即可检索对象,而无需添加任何特殊字符。

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-26
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      相关资源
      最近更新 更多