混合GlobalID ::标识表单对象

时间:2016-04-09 10:17:14

标签: ruby-on-rails ruby garbage-collection

Rails 4.2.5

我有Form对象Feedback

class Feedback
  include ActiveModel::Model
  attr_accessor :name, :message

  validates :name, :message, presence: true
end

和控制器FeedbacksController

  def create
    @feedback = Feedback.new(feedback_params)
    if @feedback.valid?
      FeedbackServiceMailer.new_feedback(@feedback).deliver_later
      redirect_to root_url, notice: 'Thanks for your feedback!'
    else
      render :index, status: 400
    end
  end

能够将@feedback对象传递给Mailer。我添加了GlobalID::Identification mixin并提供了idself.find方法:

  def id
    object_id
  end

  def self.find(id)
    ObjectSpace._id2ref(id.to_i)
  end

我的问题是,是否可以提供object_id反序列化Form对象?

据我了解,如果某些内容引用了它,Ruby GC将不会收集@feedback对象。

0 个答案:

没有答案