paperclip-globalize和activeadmin的问题

时间:2015-03-14 15:22:29

标签: ruby-on-rails paperclip activeadmin attachment globalize

我正在尝试在activeadmin中设置多语言表单上传。我的目标是能够根据语言环境(法语和英语)上传不同的pdf文件。 我创建了一个“恢复”模型并按照“paperclip-globalize

文档中的描述设置回形针和翻译属性

每次尝试上传文件时都会出现以下错误: “Resume :: Translation”的未知属性'resume'(我创建了resume_translations表)

如何让轨道理解'resume'属性应该被理解为翻译表中的paperclip属性? 我应该如何在管理文件中定义'permit_params'?

感谢您的帮助!

我的activeadmin文件

permit_params :id, translations_attributes: [
                     :id, :locale, :resume
                   ]

form do |f|
  f.semantic_errors *f.object.errors.keys

  f.inputs 'Resume' do
    f.translated_inputs 'Translated fields', switch_locale: false do |t|
      t.input :resume, as: :file,
    end
  end

  f.actions
end

我的简历模型

class Resume < ActiveRecord::Base
  belongs_to :attachable, polymorphic: true
  has_attached_file :resume,
                path: ':rails_root/public/system/:attachment/:id/:filename',
                url:  '/system/:attachment/:id/:locale/:filename',
                default_url: '/assets/images/default_media/:style/missing.png'

  validates_attachment_content_type :resume, content_type: %w(application/pdf)

  translates :resume_file_name, 
             :resume_content_type, 
             :resume_file_size, 
             :resume_updated_at, 
             fallbacks_for_empty_translations: true
  active_admin_translates :resume_file_name, 
                          :resume_content_type, 
                          :resume_file_size, 
                          :resume_updated_at, 
                          fallbacks_for_empty_translations: true
end

我的项目

  • Rails 4.2
  • Ruby 2.2.0
  • Paperclip 4.2.1
  • Globalize 5.0.1
  • Paperclip-globalize 2.2.0
  • Activeadmin-全球化

0 个答案:

没有答案