我有文件,应在更新实例属性后更新 它看起来像这样:
controller.rb
def update
if UpdateNewspaperDesign.new(newspaper_design, newspaper_design_params).call
#render response
end
end
和
class UpdateNewspaperDesign
def initialize(newspaper_design, params)
@newspaper_design = newspaper_design
@params = params
end
def call
newspaper_design.assign_attributes(params)
File.open(File.join(Rails.root, 'tmp', "newspaper-design-#{Time.now.to_i}.css"), 'w') do |file|
file.write(css(newspaper_design))
newspaper_design.css = file
end
newspaper_design.save
end
private
attr_reader :newspaper_design, :params
def css(newspaper_design)
NewspaperDesignCssCompiler.new(newspaper_design).call
end
end
然后我在布局中包含css
= stylesheet_link_tag newspaper.design.css_url, media: 'all'
正如我在控制台中看到的:css url已更新,但是在布局中插入的url不会更新。
答案 0 :(得分:0)
将文件替换为 Tempfile - 这是我修复它的方式