清单中的ArgumentError索引(缺少必需:存储桶选项)

时间:2017-02-10 08:14:05

标签: ruby-on-rails ruby amazon-s3

列表#index中的ArgumentError(缺少必需:存储桶选项) 我不确定我需要做什么。我正在使用回形针放入s3。我的错误来自第6行。如果我删除它,我不会得到错误。

<%= image_tag listing.image.url %>

index.html.erb

<div class="center">
<div class="row">
  <% @listings.each do |listing| %>
<div class="col-md-3">
  <div class="thumbnail">
    <%= image_tag listing.image.url %>
    <div class="caption">
      <h3><%= listing.name %></h3>
      <p><%= number_to_currency(listing.price) %></p>
      <%= link_to 'Show', listing, class: "btn btn-link" %>
      <%= link_to 'Edit', edit_listing_path(listing), class: "btn btn-link" %>
      <%= link_to 'Destroy', listing, method: :delete, data: {   confirm: 'Are you sure?' }, class: "btn btn-link" %>
        </div>
      </div>
    </div>
  <% end %>
</div>

<br>

<%= link_to "New Listing", new_listing_path, class: "btn btn-link" %>

模型/ listings.rb

class Listing < ActiveRecord::Base
  has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
  validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end

终端错误

Processing by ListingsController#index as HTML
  Rendering listings/index.html.erb within layouts/application
  Listing Load (1.8ms)  SELECT "listings".* FROM "listings"
  Rendered listings/index.html.erb within layouts/application (40.3ms)
Completed 500 Internal Server Error in 101ms (ActiveRecord: 1.8ms)



ActionView::Template::Error (missing required :bucket option):
    3:   <% @listings.each do |listing| %>
    4:     <div class="col-md-3">
    5:       <div class="thumbnail">
    6:         <%= image_tag listing.image.url %>
    7:         <div class="caption">
    8:           <h3><%= listing.name %></h3>
    9:           <p><%= number_to_currency(listing.price) %></p>

app/views/listings/index.html.erb:6:in `block in  _app_views_listings_index_html_erb__507566283338271176_70152811711040'
app/views/listings/index.html.erb:3:in `_app_views_listings_index_html_erb__507566283338271176_70152811711040'
  Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
   Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (8.6ms)
  Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.7ms)
  Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (4.8ms)
  Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (170.2ms)

配置/ initilizers.paperclip.rb

Paperclip::Attachment.default_options[:url] ':http://joeget.s3.amazonaws.com' 
Paperclip::Attachment.default_options[:path] = "#{Rails.root}/public/system/:class/:attachment/:id_partition/:style/:filename"
Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-east-1.amazonaws.com'

配置/环境/ development.rb

Rails.application.configure do

config.paperclip_defaults = {
  storage: :s3,
  s3_host_name: "s3_us-east-1.amazonaws.com",
  s3_credentials: {
    bucket: ENV['AWS_BUCKET'],
    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['WS_SECRET_ACCESS_KEY'],
    s3_region: ENV['AWS_REGION'], # or ENV['AWS_REGION']
  } 
  }
      # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports.
  config.consider_all_requests_local = true

  # Enable/disable caching. By default caching is disabled.
  if Rails.root.join('tmp/caching-dev.txt').exist?
    config.action_controller.perform_caching = true

    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => 'public, max-age=172800'
    }
  else
    config.action_controller.perform_caching = false

    config.cache_store = :null_store
  end

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  config.action_mailer.perform_caching = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

 # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Suppress logger output for asset requests.
  config.assets.quiet = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

1 个答案:

答案 0 :(得分:0)

根据纸夹github wikibucket配置应该是paperclip_defaults而不是s3 credentials。喜欢:

config.paperclip_defaults = {
  storage: :s3,
  s3_host_name: "s3_us-east-1.amazonaws.com",
  bucket: ENV['AWS_BUCKET'],
  s3_credentials: {
    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['WS_SECRET_ACCESS_KEY'],
    s3_region: ENV['AWS_REGION'], # or ENV['AWS_REGION']
  } 
}