【发布时间】:2019-10-14 09:25:14
【问题描述】:
在我的 Rails 5.2.2 应用程序中,我使用 Active Storage 将 logos 附加到 profiles:
class Profile < ApplicationRecord
has_many_attached :logos
end
如何测试更新时配置文件是否附加了新徽标?
现在,我正在检查我的控制器中的 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
有没有办法在 model 中做同样的事情,即检查附件是否真的是新的,然后根据它设置 logo_active 属性?
我玩弄了 Rails 的 new_record? 方法,但无济于事。
【问题讨论】:
-
您找到解决方法了吗?今天经历了这个。
标签: ruby-on-rails rails-activestorage