您好我已将其包含在我的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;
请指导我如何克服它。提前谢谢。
答案 0 :(得分:1)
<% @departments.each do |department| %>
<%= image_tag(department.attachment.attach.url)%>
<%end%>