保存在 aws-sdk 中时回形针图像不可见

Paperclip image does not visible when save in aws-sdk

您好,我已将其包含在我的 gemfile 中

gem 'paperclip', '~> 4.2'
gem 'aws-sdk', '< 2.0'

并与这些模型关联:

class Department < ActiveRecord::Base
  has_one :attachment, as: :attachable
  accepts_nested_attributes_for :attachment
end

另一个型号是:

class Attachment < ActiveRecord::Base
  belongs_to :attachable, polymorphic: true
  has_attached_file :attach,
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml",
                    :url => ":s3_domain_url",
                    :path => "/contents/:id/:basename.:extension"
  validates_attachment_content_type :attach,
                                    :content_type => ['application/msword',
                                                       'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                                                       'application/pdf',
                                                       'image/jpeg', 'image/jpg', 'image/png']
end

现在,当我将附件保存在我的数据库中时,但是当我进入我的索引页面并写下这个时

<% @departments.each do |department| %>
   <%= image_tag(department.attach.url)%>
<%end%>

它给我错误

undefined method `attach'

请指导我如何克服它。提前致谢。

<% @departments.each do |department| %>
   <%= image_tag(department.attachment.attach.url)%>
<%end%>