嗨,我目前正在为用户制作一个应用程序来上传图片。我正在尝试添加 Amazon S3 以准备部署我的应用程序。我没有收到任何错误,但在尝试设置 Amazon S3 后,我的图片无法正确上传。图片正在正确上传到亚马逊,而不是在我的数据库中,因此当我上传图片并尝试在视图中循环显示它们时,什么也没有显示。任何人都可以帮助我吗?
顺便说一句,我正在使用 Paperclip + jQuery 文件上传(用于多个图片上传)+ Amazon S3 + s3_direct_upload gem (https://github.com/WayneHoover/s3_direct_upload)
配置路线(注意图片嵌套在相册和用户中)这里没有问题
Pholder::Application.routes.draw do
resources :users do
resources :friends
resources :albums do
resources :photos
end
end
end
users/show.html.erb(应该显示我上传的图片的页面,即使在我上传后也没有显示新图片)
<% @user.albums.each do |album| %>
<div class="albumthumb">
<%= link_to image_tag(!album.photos.empty? ? album.photos.first.avatar.url(:medium) : ("questionmark.png"), :size => "150x150"), user_album_path(@user, album) %>
<br>
<%= album.name %>
</div>
<% end %>
照片/new.html.erb(这里也有问题)
#my new uploader that works with amazon s3, but doesn't seem to be storing the pics in my database
<%= s3_uploader_form post: user_album_photos_path, as: "photo[avatar]", id: "myS3Uploader" do %>
<%= file_field_tag :file, multiple: true %>
<% end %>
#this is my old upload form that worked fine when uploading pics to my local public directory.
#
#<% provide(:title, "Upload pictures") %>
#
#<%= form_for([@user, @album, @photo], :html => { :multipart => true }) do |f| %>
#
#<%= f.file_field :avatar, multiple: true, name: "photo[avatar]" %>
<div id="pics">
<%= render :partial => "photo", :collection => @photos %>
</div>
<script id="template-upload" type="text/x-tmpl">
<div class="upload">
{%=o.name%}
<div class="progress"><div class="bar" style="width: 0%"></div></div>
</div>
</script>
这是我在 github 上的代码:https ://github.com/EdmundMai/railstest/blob/master/app/views/photos/new.html.erb
如果您需要我上传更多代码,请告诉我。请帮忙!