ruby-on-rails-3 – Rails 3,Paperclip – Custom Interpolation
发布时间:2020-12-16 21:49:17 所属栏目:百科 来源:网络整理
导读:我已经遇到了一些麻烦,使自定义插值,通过我可以在网上找到的每一个例子,但无论我做了什么,没有成功. 目前我有这个: 模型 has_attached_file :photo,:path = ":rails_root/public/images/:img_name-:style.:extension",:styles = { :original = '100x100',:t
我已经遇到了一些麻烦,使自定义插值,通过我可以在网上找到的每一个例子,但无论我做了什么,没有成功.
目前我有这个: 模型 has_attached_file :photo,:path => ":rails_root/public/images/:img_name-:style.:extension",:styles => { :original => '100x100',:thumb => '30x30' } 初始化/ paperclip.rb Paperclip.interpolates :img_name do |attachment,style| attachment.instance.img_name end img_name是使用图像上传的形式填充的字段.
解决方法
如果直接在模型中似乎工作:
class Model < ActiveRecord::Base Paperclip.interpolates :img_name do |attachment,style| attachment.instance.img_name end has_attached_file :photo,:styles => { :original => '100x100',:thumb => '30x30' } end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |