2015-03-03 41 views
1

我需要幫助。我正在創建一個使用ruby和amazon web服務的示例書店。我已經安裝了gem'aws-sdk',一切正常,直到我嘗試用圖像和資源創建新書。我收到link上列出的錯誤。 「app/controllers/books_controller.rb:29:在'create'」(對不起,我添加了完整跟蹤,因爲我認爲這會有所幫助)如果我刪除它建議的代碼行,它可以工作,但書不會在儀表板中顯示。在Ruby中添加圖像和資源後,我無法保存圖書

讓我知道你是否需要我的任何東西。我沒有把最新的提交推送到github上,因爲我不想要任何錯誤,但是如果需要的話,我會的。 Here是沒有這些功能的最新回購。

下面是我採取的步驟來達到這一點。也許我錯過了什麼? 添加AWS-SDK寶石我的Gemfile

設置回形針默認爲AWS S3並設置其憑據

應用程序/配置/ apllication.rb

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

添加兩個附件(:圖像/:資源)的輸入欄的簿冊形式

<%= simple_form_for(@book, html: {class: "form-signin"}) do |f| %> 
<%= f.error_notification %> 


<%= f.input :name, required: true, label: false, placeholder: "Name", input_html: {class: "form-control"} %> 
<%= f.input :author, required: true, label: false, placeholder: "Author's name", input_html: {class: "form-control"} %> 
<%= f.input :description, required: true, label: false, placeholder: "Description", input_html: {class: "form-control", rows: 5} %> 
<br> 
<%= f.input :price, required: true, label: false, placeholder: "Price", input_html: {class: "form-control"} %> 
<%= f.input :image %> 
<%= f.input :resource %> 
<div class="checkbox text-center"> 
<p>Availability</p> 
<%= f.input :availability, required: false, label: false %> 
</div> 
<%= f.button :submit, class: "btn btn-primary btn-block" %> 
<% end %> 

驗證內容類型的附件,以及它們的存在

validates_attachment_content_type :image, 
content_type: /^image\/(png|gif|jpeg)/, 
message: "Only images allowed" 

validates_attachment_content_type :resource, 
content_type: ['application/pdf'], 
message: "Only pdfs allowed" 

validates :image, attachment_presence: true 
validates :resource, attachment_presence: true 

然後是錯誤,當我嘗試創建一個新的書「的書籍/新」

UPDATE:

這裏是我的終端出認沽當我點擊「創建書」

jshuadvd:estuk joshuadavid$ rails s 
=> Booting WEBrick 
=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000 
=> Run `rails server -h` for more startup options 
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) 
=> Ctrl-C to shutdown server 
[2015-03-02 21:10:03] INFO WEBrick 1.3.1 
[2015-03-02 21:10:03] INFO ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0] 
[2015-03-02 21:10:03] INFO WEBrick::HTTPServer#start: pid=30712 port=3000 


Started GET "/books/new" for 127.0.0.1 at 2015-03-02 21:10:10 -0800 
    ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" 
Processing by BooksController#new as HTML 
    User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1 
    Rendered books/_form.html.erb (71.2ms) 
    Rendered books/new.html.erb within layouts/application (75.0ms) 
    Rendered layouts/_header.html.erb (1.1ms) 
Completed 200 OK in 389ms (Views: 354.1ms | ActiveRecord: 1.0ms) 


Started POST "/books" for 127.0.0.1 at 2015-03-02 21:10:55 -0800 
Processing by BooksController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"9WlfCy70fc+OZdNVq8vXpLGWGB6ifUBffQ4M5E/71XU=", "book"=>{"name"=>"The Book of Ruby", "author"=>"Huw Collingbourne", "description"=>"A Book of Ruby", "price"=>"1299", "image"=>#<ActionDispatch::Http::UploadedFile:0x007fa14a9a7a98 @tempfile=#<Tempfile:/var/folders/1z/dl8cfs4n3b53d8lqr4l8mbfr0000gq/T/RackMultipart20150302-30712-wp2ftx>, @original_filename="ruby_frontcvr.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"book[image]\"; filename=\"ruby_frontcvr.png\"\r\nContent-Type: image/png\r\n">, "resource"=>#<ActionDispatch::Http::UploadedFile:0x007fa14a9a7908 @tempfile=#<Tempfile:/var/folders/1z/dl8cfs4n3b53d8lqr4l8mbfr0000gq/T/RackMultipart20150302-30712-soog2z>, @original_filename="The Book of Ruby.pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"book[resource]\"; filename=\"The Book of Ruby.pdf\"\r\nContent-Type: application/pdf\r\n">, "availability"=>"1"}, "commit"=>"Create Book"} 
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1 
Command :: file -b --mime '/var/folders/1z/dl8cfs4n3b53d8lqr4l8mbfr0000gq/T/cf4baff8e3f9d6dc5ecb7be1577b42fa20150302-30712-1rfuyrq.png' 
Command :: file -b --mime '/var/folders/1z/dl8cfs4n3b53d8lqr4l8mbfr0000gq/T/b5e2665470b6cb72f39833d889a4b7f620150302-30712-ghgiut.pdf' 
    (0.1ms) begin transaction 
Command :: file -b --mime '/var/folders/1z/dl8cfs4n3b53d8lqr4l8mbfr0000gq/T/cf4baff8e3f9d6dc5ecb7be1577b42fa20150302-30712-x17x01.png' 
Command :: file -b --mime '/var/folders/1z/dl8cfs4n3b53d8lqr4l8mbfr0000gq/T/b5e2665470b6cb72f39833d889a4b7f620150302-30712-1pncf55.pdf' 
Binary data inserted for `string` type on column `image_content_type` 
Binary data inserted for `string` type on column `resource_content_type` 
    SQL (0.7ms) INSERT INTO "books" ("author", "created_at", "description", "image_content_type", "image_file_name", "image_file_size", "image_updated_at", "name", "price", "resource_content_type", "resource_file_name", "resource_file_size", "resource_updated_at", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["author", "Huw Collingbourne"], ["created_at", "2015-03-03 05:10:56.007365"], ["description", "A Book of Ruby"], ["image_content_type", "image/png"], ["image_file_name", "ruby_frontcvr.png"], ["image_file_size", 86035], ["image_updated_at", "2015-03-03 05:10:55.920455"], ["name", "The Book of Ruby"], ["price", 1299], ["resource_content_type", "application/pdf"], ["resource_file_name", "The_Book_of_Ruby.pdf"], ["resource_file_size", 8184750], ["resource_updated_at", "2015-03-03 05:10:55.959655"], ["updated_at", "2015-03-03 05:10:56.007365"], ["user_id", 1]] 
[paperclip] saving /books/images/000/000/006/original/ruby_frontcvr.png 
[AWS S3 301 0.424533 0 retries] put_object(:acl=>:public_read,:bucket_name=>"jdi.development",:content_length=>86035,:content_type=>"image/png",:data=>Paperclip::UploadedFileAdapter: ruby_frontcvr.png,:key=>"books/images/000/000/006/original/ruby_frontcvr.png") AWS::S3::Errors::PermanentRedirect The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. 

    (1.1ms) rollback transaction 
Completed 500 Internal Server Error in 710ms 

AWS::S3::Errors::PermanentRedirect (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.): 
    app/controllers/books_controller.rb:29:in `create' 


    Rendered /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.6ms) 
    Rendered /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.3ms) 
    Rendered /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms) 
    Rendered /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.4ms) 

回答

0

我決定的問題。我重新創建了桶。您必須將區域設置爲「美國標準」才能使用。最初它被設置爲「俄勒岡州」。