2013-01-25 78 views
1

我試圖找出爲什麼我的照片沒有顯示在S3上。當我檢查(不存在的)圖片時,它顯示了正確的亞馬遜s3路徑,但圖像從未上傳到s3。當我輸入heroku logs - tail到我的控制檯時,沒有明顯的錯誤。我也已經在heroku上設置了s3變量。 heroku日誌看起來與我上傳音樂文件的其他網站完全相同,但文件從未在S3上顯示...使用回形針上傳到s3後圖像不顯示

這裏是github頁面,如果您喜歡在那裏閱讀。謝謝!

上傳後的Heroku日誌。我從其他應用程序中看到的唯一明顯區別是,此應用程序首先重定向,然後回形針保存attatchments。

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 %> 

回答

0

好吧,我解決我自己的問題。

我不得不刪除我的原桶和作出新的桶用一個新名稱,然後我就到我的aws_bucket變量重新在Heroku上的配置與

heroku config:add AWS_BUCKET=newbucketname 

現在,它完美的作品!

+0

爲什麼要刪除舊的? – ImranNaqvi

相關問題