ruby - Rails 5 Fog CarrierWave Photo Upload to Amazon S3 no implicit conversion of String into Array -
i absolute beginner of ruby on rails. there error encountered , not know deal with.
what i'd do: uploading photo amazon s3 bucket.
error: no implicit conversion of array string.
the error comes out when @prototype.save fails in prototype#create action in prototypes_controller.rb
question: in order solve issue, when should convert array string?
the params displayed in webrick server.
{"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"}
here files might have error.
prototype_controller.rb
def create @prototype = current_user.prototypes.new(prototype_params) if @prototype.save flash[:notice] = 'prototype created.' redirect_to root_path else flash[:alert] = 'prototype not 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
config/initializer/carrierwave.rb
require 'carrierwave/storage/abstract' require 'carrierwave/storage/file' require 'carrierwave/storage/fog' carrierwave.configure |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
backtrace
{"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`.* `users` `users`.`id` = 2 order `users`.`id` asc limit 1 begin sql (0.3ms) insert `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 `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 string): app/controllers/prototypes_controller.rb:24:in `create'
if has encountered error below, can give me clues? advice appreciated! in advance!
i suggest add following lines inside carrierwave.configure
block:
config.ignore_integrity_errors = false config.ignore_processing_errors = false config.ignore_download_errors = false
it more understandable error.
Comments
Post a Comment