首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ArgumentError in Listings#index (缺少必需:桶选项)

ArgumentError in Listings#index (缺少必需:桶选项)
EN

Stack Overflow用户
提问于 2017-02-10 08:14:05
回答 1查看 111关注 0票数 0

ArgumentError in Listings#index (缺少必需的:桶选项)--我不确定我需要做什么。我正在把s3和回形针放在一起。我的错误来自第6行。如果删除它,就不会得到错误。

代码语言:javascript
复制
<%= image_tag listing.image.url %>

index.html.erb

代码语言:javascript
复制
<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" %>

models/listings.rb

代码语言:javascript
复制
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

终端误差

代码语言:javascript
复制
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)

config/initilizers.paperclip.rb

代码语言:javascript
复制
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'

config/environment/development.rb

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-10 10:08:47

根据回形针github 维基bucket配置应该用于paperclip_defaults而不是s3 credentials。像这样:

代码语言:javascript
复制
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']
  } 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42154514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档