ArgumentError(缺少必需的选项:名称)

ArgumentError (missing required option :name)

我已经在 Heroku 上部署了一个基本的画廊网站,但是图片上传功能无法正常工作,它给我 500 内部服务器错误,这一切都在本地服务器上工作。我正在使用 AWS S3 存储桶进行存储。

我的上传文件

class PortfolioUploader < CarrierWave::Uploader::Base

  storage :aws

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url(*args)
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end
  def extension_whitelist
    %w(jpg jpeg gif png)
  end
end

控制器文件创建方法

  def create
    @portfolio_item = Portfolio.new(portfolio_params)
    if @portfolio_item.save
      redirect_to portfolios_path
    else
      render :new
    end
  end

-------------------------------------------- ---------------------------------------------- ----------carrierwave.rb 文件

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV.fetch('S3_BUCKET_NAME') # for AWS-side bucket access permissions config, see section below
  config.aws_acl    = 'private'
  config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7
  config.aws_attributes = -> { {
    expires: 1.week.from_now.httpdate,
    cache_control: 'max-age=604800'
  } }

  config.aws_credentials = {
    access_key_id:     ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    region:            ENV.fetch('AWS_REGION'), # Required
    stub_responses:    Rails.env.test? # Optional, avoid hitting S3 actual during tests
  }
end

2020-11-05T10:35:32.467646+00:00 app[web.1]: F, [2020-11-05T10:35:32.467563 #4] FATAL -- : [421e9f92-f540-4552-aa31-be18534786e4]
2020-11-05T10:35:32.467647+00:00 app[web.1]: [421e9f92-f540-4552-aa31-be18534786e4] ArgumentError (missing required option :name):
2020-11-05T10:35:32.467648+00:00 app[web.1]: [421e9f92-f540-4552-aa31-be18534786e4]
2020-11-05T10:35:32.467648+00:00 app[web.1]: [421e9f92-f540-4552-aa31-be18534786e4] app/controllers/portfolios_controller.rb:26:in `create'```

当您调用 portfolio_params 时,您似乎没有传递名称,而名称是创建投资组合的必填字段。

你能分享一个输入创建方法时的参数示例以及来自控制器的 portfolio_params 方法吗?