[英]Paperclip for Rails: Can I access the model?
Let's say I have a model called Theme, which has several attributes setting interface colors. 假设我有一个名为Theme的模型,它有几个设置界面颜色的属性。 Theme also has a Paperclip attachment, which is a user-generated CSS template. 主题还有一个Paperclip附件,它是用户生成的CSS模板。 I want to set up a processor to generate a final CSS file, inserting the interface colors into the user-generated template. 我想设置一个处理器来生成最终的CSS文件,将界面颜色插入到用户生成的模板中。 To do this, I need to access the model data from within the processor. 为此,我需要从处理器中访问模型数据。 Is this possible? 这可能吗?
The processor has an accessor called attachment
this points back to the instance of Paperclip::Attachment. 处理器有一个名为attachment
它指向Paperclip :: Attachment的实例。 The attachment in turn has an accessor instance
which points to the instance of the original model. 该附件又具有一个指向原始模型实例的存取器instance
。 So all you should have to do from the processor is call attachment.instance
to get the original model. 因此,您需要从处理器执行的操作是调用attachment.instance
来获取原始模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.