简体   繁体   English

延迟作业向Rails对象添加特殊字符

[英]Delayed Job adding special characters to rails object

I queue a delayed job task that saves an objects json representation to s3. 我将一个延迟的作业任务排队,该任务将对象json表示形式保存到s3。 One of the attributes for the object is copyright_info, which includes a copyright symbol. 对象的属性之一是copyright_info,其中包括版权符号。 The copyright symbol appears fine in the database and if I 'puts object.copyright_info' in the controller, but when I 'puts object.copyright_info' in the delayed job file it has added special characters. 如果我在控制器中“放入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

Save json file: 保存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

I'm running on Heroku with ruby-1.9.2-p32 and Postgresql. 我正在使用ruby-1.9.2-p32和Postgresql在Heroku上运行。 When I do this same task locally, special characters do not seem to be added. 当我在本地执行此相同任务时,似乎没有添加特殊字符。

Any ideas? 有任何想法吗?

I solved my problem by simply passing the object ID rather than the full object to the Struct.new() class. 我通过简单地将对象ID而不是完整对象传递给Struct.new()类来解决了我的问题。 Once I had the ID in the SaveS3Json class, I simply did a normal Active Record .find(id) and the object was retrieved without any special characters added. 在SaveS3Json类中获得ID后,我只需执行常规的Active Record .find(id),即可检索该对象,而无需添加任何特殊字符。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM