2017-08-15 15 views
0

私はRuby on Railsの初心者です。 私は遭遇した、そして対処することを知らないエラーがあります。Rails 5 Fog CarrierWave写真Amazon S3へのアップロード文字列の配列への暗黙的変換なし

どうすればいいですか:Amazon S3バケットに写真をアップロードしています。

エラー:暗黙的にArrayを文字列に変換しない。まさに私が文字列に配列を変換する必要がある場合、この問題を解決するために、

エラーがprototype.saveプロトタイプ#に失敗したとき@ prototypes_controller.rb

質問でアクションを作成出てきますか?

Webrickサーバーに表示されるパラメータ。

{"utf8"=>"✓", 
"prototype"=> 
    {"name"=>"dafda", 
    "prototype_images_attributes"=> 
     {"0"=> 
     {"content"=> 
      #<ActionDispatch::Http::UploadedFile:0x007fe07491b778 
      @content_type="image/jpeg", 
      @headers="Content-Disposition: form-data; name=\"prototype[prototype_images_attributes][0][content]\"; filename=\"card100002057_1.jpg\"\r\nContent-Type: image/jpeg\r\n", 
      @original_filename="card100002057_1.jpg", 
      @tempfile=#<File:/var/folders/yy/42bpgmdj4t16rf0_5xsly3tc0000gp/T/RackMultipart20170815-70968-fzdoey.jpg>>, 
     "status"=>"main"}, 
     "1"=>{"status"=>"sub"}, 
     "2"=>{"status"=>"sub"}}, 
    "catchcopy"=>"fdafda", 
    "concept"=>"fdafda"}, 
    "commit"=>"Publish"} 

エラーが発生した可能性のあるファイルは次のとおりです。

prototype_controller.rb

def create 
    @prototype = current_user.prototypes.new(prototype_params) 

    if @prototype.save 
    flash[:notice] = 'Prototype was successfully created.' 
    redirect_to root_path 
    else 
    flash[:alert] = 'Prototype was not successfully created.' 
    render :new 
    end 
end 

private 
def prototype_params 
    params.require(:prototype) 
    .permit(:name, 
      :catchcopy, 
      :concept, 
      prototype_images_attributes: [:content, :status] 
    ) 
end 

def set_prototype 
    @prototype = Prototype.find(params[:id]).decorate 
end 

prototype_image_uploader.rb

class PrototypeImageUploader < CarrierWave::Uploader::Base 
    storage :fog 

    def store_dir 
    'uploads' 
    end 

    def extension_whitelist 
    %w(jpg jpeg gif png) 
    end 
end 

設定/初期化/ carrierwave.rb

require 'carrierwave/storage/abstract' 
require 'carrierwave/storage/file' 
require 'carrierwave/storage/fog' 

CarrierWave.configure do |config| 
    config.storage = :fog 
    config.fog_credentials = { 
    provider: 'AWS', 
    aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], 
    aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 
    region: 'ap-northeast-1' 
    } 

    case Rails.env 
    when 'production' 
     config.fog_directory = ENV['S3_BUCKET'], 
     config.asset_host = ENV['S3_BUCKET_HOST'] 
    when 'development' 
     config.fog_directory = ENV['S3_BUCKET'], 
     config.asset_host = ENV['S3_BUCKET_HOST'] 
    when 'test' 
     config.storage = :file 
    end 
end 

バックトレース

{"utf8"=>"✓", 
"prototype"=> 
    {"name"=>"dafda", 
    "prototype_images_attributes"=> 
     {"0"=> 
     {"content"=> 
      #<ActionDispatch::Http::UploadedFile:0x007fe07491b778 
      @content_type="image/jpeg", 
      @headers="Content-Disposition: form-data; name=\"prototype[prototype_images_attributes][0][content]\"; filename=\"card100002057_1.jpg\"\r\nContent-Type: image/jpeg\r\n", 
      @original_filename="card100002057_1.jpg", 
      @tempfile=#<File:/var/folders/yy/42bpgmdj4t16rf0_5xsly3tc0000gp/T/RackMultipart20170815-70968-fzdoey.jpg>>, 
     "status"=>"main"}, 
     "1"=>{"status"=>"sub"}, 
     "2"=>{"status"=>"sub"}}, 
    "catchcopy"=>"fdafda", 
    "concept"=>"fdafda"}, 
    "commit"=>"Publish"} 
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1 
    BEGIN 
    SQL (0.3ms) INSERT INTO `prototypes` (`name`, `catchcopy`, 
`concept`, `created_at`, `updated_at`, `user_id`) VALUES ('fdfad', 
'fdfad', 'fdfd', '2017-08-15 13:05:29', '2017-08-15 13:05:29', 2) 
    SQL (0.2ms) INSERT INTO `prototype_images` (`content`, 
`prototype_id`, `created_at`, `updated_at`, `status`) VALUES 
('13248473_1049158575176323_1670750882476661352_o.jpg', 56, '2017-08- 
15 13:05:29', '2017-08-15 13:05:29', 0) 
(0.6ms) ROLLBACK 
Completed 500 Internal Server Error in 32ms (ActiveRecord: 2.0ms) 

TypeError (no implicit conversion of Array into String): 

app/controllers/prototypes_controller.rb:24:in `create' 

誰かが以下のエラーに遭遇した場合は、手がかりを教えていただけますか? アドバイスをいただければ幸いです!前もって感謝します!

+0

エラーのバックトレースを添付してください。あなたの問題を解決するために役立つかもしれません。 – iskvmk

+0

上記の質問に付けました。それが助けになることを願っています。 – ILoveBaymax

答えて

0

私はあなたがCarrierWave.configureブロック内で以下の行を追加することをお勧め:

config.ignore_integrity_errors = false 
    config.ignore_processing_errors = false 
    config.ignore_download_errors = false 

それはより理解し、エラーを取得することに役立つ可能性があります。

+0

ありがとうございました。しかし、同じエラーが発生しました...これらのプロパティをfalseに設定しても、詳細な情報は得られません... – ILoveBaymax

関連する問題