我虽然将Paperclip属性移动到转换表,但这可能有效,但我不认为当Paperclip需要删除附件时这会起作用.
实现类似目标的最佳方法是什么?
更新:要清楚,我想要这个,因为我的客户想要为每个区域设置上传不同的图像.
解决方法 不幸的是,我没有找到使用Globalize3的方法.从理论上讲,我可以为图像添加一个单独的模型,并将image_ID添加到已翻译列的列表中(有类似于MainModel – > Translation – > Image),但似乎Globalize在非字符串列中存在一些迁移问题.我没有使用Globalize3,而是使用带有locale属性的单独Image模型和接受嵌套属性的主模型.有点像:
class MainModel < ActiveRecord::Base has_many :main_model_images accepts_nested_attributes_for :main_model_images # return image for locale or any other as a fallback def localized_image(locale) promo_Box_images.where(:locale => locale).first || promo_Box_images.first endendclass MainModelimage < ActiveRecord::Base belongs_to :main_model has_attached_file :image valIDates :locale,:presence => true,:uniqueness => { :scope => :main_model_ID }end
棘手的部分是获取表单只接受一个图像的嵌套属性,而不是has_many关系中的所有图像.
=f.fIElds_for :main_model_images,@main_model.image_for_locale(I18n.locale) do |f_image| =f_image.hIDden_fIEld :locale =f_image.label :image总结
以上是内存溢出为你收集整理的ruby-on-rails – 如何使用Globalize3制作本地化的Paperclip附件?全部内容,希望文章能够帮你解决ruby-on-rails – 如何使用Globalize3制作本地化的Paperclip附件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)