如何检查Rails的ActiveStorage中的附件是否是新的?

Tin*_*n81 5 ruby-on-rails rails-activestorage

在我的 Rails 5.2.2 应用程序中,我使用 Active Storage 附加logosprofiles

class Profile < ApplicationRecord

  has_many_attached :logos

end
Run Code Online (Sandbox Code Playgroud)

如何测试更新时个人资料中是否附加了新徽标?

现在,我正在检查logos控制器中是否有一个工作正常的参数:

class ProfileController < ApplicationController

  def update
    if params[:profile][:logos].present?
      @profile.logo_active = true # This is the important attribute I need to set
    end
    if @profile.update(profile_params)
      flash[:success] = "Profile updated."
      redirect_to profile_path
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

有没有办法在模型中执行相同的操作,即检查附件是否实际上是新的,然后logo_active根据该附件设置属性?

我尝试了 Rails 的new_record?方法,但没有成功。