【发布时间】:2012-06-21 03:34:35
【问题描述】:
我有一个脚本,我可以从中加载我的 rails 环境。 (
当我构建附件并保存其父级时,附件样式始终为 ["100>", "jpg"]
我的脚本:
require './config/environment.rb'
house = House.find(1)
house.attachments.build(doc: File.new('myfile.pdf'), category_id: 2)
house.save
型号
House < AR::Base
has_many :attachments, :as => :attachable
end
Attachment < AR::Base
### has_attached_file :doc, styles: lambda {|attachment| {thumb: (attachment.instance.category_id == 2 ? ["500>", 'jpg'] : ['100>', 'jpg']} )}
has_attached_file :doc, styles: lambda {|attachment| {thumb: (attachment.instance.category_id == 2 ? ["500>", 'jpg'] : ['100>', 'jpg'] )}} #category_id is always nil at this point but still still saves in the database
belongs_to :attachable, polymorphic: true
end
我猜我在这里忽略了一些愚蠢的事情,但我会很感激任何指针:)
【问题讨论】: