【发布时间】:2018-11-18 15:12:35
【问题描述】:
我将 ActiveStorage 用于用户生成的样式表,这些样式表将上传到 s3,以便将它们包含在自定义用户样式的网页中。
所以我有一个模型CustomeTheme
has_one_attached :style, dependent: :purge_later
还有一个 after_save 回调,在保存自定义样式后进行上传
self.style.attach(io: File.open(File.join(asset_path, name)), filename: name, content_type: 'text/css')
包含在布局中
= stylesheet_link_tag url_for(@custom_theme.style)
现在的问题是,用户保存样式并看到自定义网页的预览,但没有自定义样式(此时为 404),因为上传到 s3 尚未完成,至少是这样我想什么。
to_model delegated to attachment, but attachment is nil
/usr/local/bundle/gems/activesupport-5.2.1/lib/active_support/core_ext/module/delegation.rb:278:in `rescue in method_missing'
/usr/local/bundle/gems/activesupport-5.2.1/lib/active_support/core_ext/module/delegation.rb:274:in `method_missing'
/usr/local/bundle/gems/actionpack-5.2.1/lib/action_dispatch/routing/polymorphic_routes.rb:265:in `handle_model'
/usr/local/bundle/gems/actionpack-5.2.1/lib/action_dispatch/routing/polymorphic_routes.rb:280:in `handle_model_call'
/usr/local/bundle/gems/actionview-5.2.1/lib/action_view/routing_url_for.rb:117:in `url_for'
所以我仍然不清楚这个问题,我怎么知道资产(无论是样式还是图像)已准备好显示?
【问题讨论】:
-
保存后的样式怎么用?你没有显示代码。日志显示什么?您是否看到保存后正在运行分析作业?你检查文件路径和url是否正确?
-
@arieljuod 我刚刚更新了这个问题。分析作业成功运行,上传通常成功,但为时已晚,这就是我的怀疑,因为我可以在几个请求/秒后看到样式
标签: ruby-on-rails ruby-on-rails-5 rails-activestorage