保存在aws-sdk中时,无法看到回形针图像

时间:2015-06-08 07:42:45

标签: ruby-on-rails amazon-web-services paperclip

您好我已将其包含在我的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%>

它给了我错误

  

未定义的方法`attach&#39;

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

1 个答案:

答案 0 :(得分:1)

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