在我的rails 4应用程序中,我有一个名为ListingInformationForm的模型。在这种形式中,我希望用户上传他们工厂的徽标和图片。我在AWS S3上使用paperclip gem。目前,当我提交表单时,它将第二个图像(loan_image)的AWS S3链接保存到徽标和loan_image。
listing_information_form.rb
class ListingInformationForm < ActiveRecord::Base
# Image uploading
has_attached_file :logo,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :s3,
:url => ":s3_domain_url",
:path => "images/:class/:id.:style.:extension"
has_attached_file :loan_image,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :s3,
:url => ":s3_domain_url",
:path => "images/:class/:id.:style.:extension"
# Assocations
belongs_to :business
end
new.html.erb
<%= form_for @listing_information_form, url: business_listing_information_form_path(@user), :html => { :multipart => true } do |f| %>
<%= f.hidden_field :business_id, :value => @user.id %>
<%= f.hidden_field :loan_id, :value => @loan_id %>
<div class="reg-header">
<h2>Tell us about your business.</h2>
<p>The application will only take 10 minutes of your time!</p>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-5">
<%= f.label :logo, :class => "control-label required" %>
</div>
<div class="col-md-7">
<%= f.file_field :logo %>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-5">
<%= f.label :loan_image, :class => "control-label required" %>
</div>
<div class="col-md-7">
<%= f.file_field :loan_image %>
</div>
</div>
</div>
<% end %>
listing_information_forms_controller.rb
def listing_information_form_params
params.require(:listing_information_form).permit(:business_id, :loan_id, :logo, :loan_image)
end
答案 0 :(得分:1)
我想这是因为logo和loan_image的'path'属性都是相同的:
:path => "images/:class/:id.:style.:extension"
将它们更改为:
:path => "logos/:id.:style.:extension"
用于徽标
和
:path => "loan_images/:id.:style.:extension"
贷款图片