简体   繁体   English

Rails:Amazon S3 + Paperclip不在数据库中存储任何内容吗?

[英]Rails: Amazon S3 + Paperclip not storing anything in database?

Hi I'm currently making an app for users to upload pics. 嗨,我目前正在制作一个供用户上传照片的应用程序。 I'm trying to add Amazon S3 in preparation to deploy my app. 我正在尝试添加Amazon S3以准备部署我的应用程序。 I'm not getting any error, but after trying to set up Amazon S3 my pics aren't uploading properly. 我没有收到任何错误,但是尝试设置Amazon S3后,我的照片无法正确上传。 The pics are uploading properly onto Amazon, not in my database so that when I upload the pics and try to loop through them in the views to show them, nothing shows. 图片已正确上传到Amazon,而不是我的数据库中,因此当我上传图片并尝试在视图中循环显示它们时,什么也没有显示。 Can anyone assist me? 谁能帮助我?

Just as a sidenote, I'm using Paperclip + jQuery file upload (for multiple pic uploads) + Amazon S3 + a s3_direct_upload gem (https://github.com/WayneHoover/s3_direct_upload) 就像一个旁注一样,我正在使用回形针+ jQuery文件上传(用于多个图片上传)+ Amazon S3 + s3_direct_upload gem(https://github.com/WayneHoover/s3_direct_upload)

config routes (notice that pics is nested in albums and users) no issue here 配置路由(注意图片嵌套在相册和用户中)在这里没有问题

Pholder::Application.routes.draw do
resources :users do
  resources :friends
  resources :albums do
    resources :photos
  end
end
end

users/show.html.erb (the page that is supposed to show my uploaded pics, no new pics are showing up even after my uploads) 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 %>

photos/new.html.erb (issue here as well) photos / 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>

Here's my code on github: https://github.com/EdmundMai/railstest/blob/master/app/views/photos/new.html.erb 这是我在github上的代码: https : //github.com/EdmundMai/railstest/blob/master/app/views/photos/new.html.erb

Let me know if you need me to upload any more code. 让我知道您是否需要我上传更多代码。 Please help! 请帮忙!

JQuery file upload just uploads the files to Amazon S3: it doesn't add the required Paperclip records to the database. jQuery文件上传只是将文件上传到Amazon S3:不会将所需的Paperclip记录添加到数据库。 To do that, you need to do a few more steps. 为此,您需要执行一些其他步骤。 See the jquery-fileupload-rails-paperclip-example or jQuery File Upload v4 for Rails 3 . 请参阅jquery-fileupload-rails-paperclip-exampleRails 3的jQuery File Upload v4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM