1

私の写真がS3に表示されない理由を見つけようとしています。(存在しない) 画像を調べると、正しい Amazon s3 パスが表示されますが、画像が s3 にアップロードされることはありません。コンソールに heroku logs --tail と入力しても、明らかなエラーはありません。また、heroku で s3 変数を既に設定しています。heroku のログは、音楽ファイルをアップロードする他の Web サイトと同じように見えますが、ファイルが S3 に表示されることはありません...

そこで読みたい場合は、こちらのgithubページを参照してください。ありがとう!

アップロード後の Heroku ログ。他のアプリとの唯一の違いは、このアプリが最初にリダイレクトしてから、クリップが添付ファイルを保存することです。

Started POST "/restaurants/3/menuitems" for 68.38.119.33 at 2013-01-25 16:36:07 +0000
2013-01-25T16:36:07+00:00 app[web.1]: Processing by MenuitemsController#create as HTML
2013-01-25T16:36:07+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"I8iVlAdNa/ui96aflFAlPxfAIgmvOB4k/Y7Fhf5ElMI=", "menuitem"=>{"name"=>"Penne alla Vodkas", "description"=>"Fresh oven baked bread with a kiss of mother nature cut into fresh little delicious strips.", "image"=>#<ActionDispatch::Http::UploadedFile:0x00000005ff55f0 @original_filename="penneallavodka.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"menuitem[image]\"; filename=\"penneallavodka.jpeg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20130125-2-1xa5s3v>>, "price"=>"10.95"}, "commit"=>"Add Item", "restaurant_id"=>"3"}
2013-01-25T16:36:11+00:00 app[web.1]: Redirected to http://sugarcider.com/restaurants/3
2013-01-25T16:36:11+00:00 app[web.1]: Completed 302 Found in 4129ms (ActiveRecord: 18.1ms)
2013-01-25T16:36:11+00:00 app[web.1]: [paperclip] Saving attachments.
2013-01-25T16:36:11+00:00 app[web.1]: [paperclip] saving penneallavodka.jpeg
2013-01-25T16:36:11+00:00 app[web.1]: [AWS S3 200 4.101325 0 retries] put_object(:acl=>:public_read,:bucket_name=>"restaurantimages",:content_length=>818276,:content_type=>"image/jpeg",:data=>#<Paperclip::UploadedFileAdapter:0x00000006322908 @target=#<ActionDispatch::Http::UploadedFile:0x00000005ff55f0 @original_filename="penneallavodka.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"menuitem[image]\"; filename=\"penneallavodka.jpeg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20130125-2-1xa5s3v>>, @tempfile=#<File:/tmp/penneallavodka20130125-2-mfgg7i.jpeg>>,:key=>"penneallavodka.jpeg")  

メニュー項目モデル

class Menuitem < ActiveRecord::Base
  attr_accessible :name, :description, :price, :image

  belongs_to :restaurant

  has_attached_file :image,
    :styles => {
      :thumbnail => '100x101>',
      :regular => '560x568>'
    },
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['AWS_BUCKET'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    },
    :path => ":filename.:extension"
end

New.html.erb

<%= form_for [@restaurant, @restaurant.menuitems.new], :html => { :multipart => true } do |f| %>
  <%= f.label :name %><br/>
  <%= f.text_field :name %><br/>
  <%= f.label :description %><br/>
  <%= f.text_field :description %><br/>
  <%= f.label :image %><br/>
  <%= f.file_field :image %><br/>
  <%= f.label :price %><br/>
  <%= f.text_field :price %><br/>
  <%= f.submit 'Add Item', :class => 'btn btn-large btn-success' %>
<% end %>

Menuitems_controller.rb

  def new
    @restaurant = Restaurant.find(params[:restaurant_id])
    @menuitem = @restaurant.menuitems.build
  end

  def create
    @restaurant = Restaurant.find(params[:restaurant_id])
    @menuitem = @restaurant.menuitems.build(params[:menuitem])
    respond_to do |format|
      if @menuitem.save
        format.html { redirect_to restaurant_path(@restaurant) }
      else
        format.html { redirect_to restaurant_path(@restaurant), notice: 'One or more fields are not correctly formatted.' }
      end
    end
  end

  def index
    @restaurant = Restaurant.find(params[:restaurant_id])
    @menuitems = @restaurant.menuitems.build
  end

これは production.rb にあります

  config.paperclip_defaults = {
    :storage => :s3,
    :s3_protocol => 'http',
    :s3_credentials => {
      :bucket => ENV['AWS_BUCKET'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
  }

レストランの index.html

  <% @menuitems.each do |f| %>
    <tr>
      <td><%= f.name %></td>
      <td><%= f.description %></td>
      <td>$<%= f.price %></td>
      <td><%= image_tag f.image.url(:regular) %></td>
      <td><%= link_to 'Destroy', restaurant_menuitem_path(f), :method => :delete, :class => 'btn btn-danger' %>
      <%= link_to 'Edit', edit_restaurant_menuitem_path(f), :class => 'btn btn-success'%></td>
    </tr>
  <% end %>
4

1 に答える 1

0

わかりました、私は自分の問題を解決しました。

元のバケットを削除して新しい名前で新しいバケットを作成する必要がありました。次に、herokuconfigのaws_bucket変数をリセットする必要がありました。

heroku config:add AWS_BUCKET=newbucketname

今では完璧に動作します!

于 2013-01-25T16:51:47.337 に答える