J'ai eu affaire à un problème où j'ai l'erreur: "pas de conversion implicite de String en Array". Pour mettre cela en contexte: Je suis sur Rails 4.1.0.beta1, et j'utilise Paperclip. J'essaie d'ajouter un filigrane à mes images. J'ai trouvé la solution suivante: Watermark images with paperclip, rails 4pas de conversion implicite de String en Array - Rails 4.1.0.beta1
Je sorte sorte de travailler à un certain point la nuit dernière après avoir reçu le message d'erreur ici déclaré - puis j'ai fait un léger changement, que j'avais défait. Et maintenant je reçois à nouveau l'erreur suivante ?! Ce pourrait être facile, mais je ne semble pas le voir.
Toute aide serait grandement appréciée.
Voici le message d'erreur:
Completed 500 Internal Server Error in 578ms TypeError - no implicit conversion of String into Array:() Users/georg/Development/RoR/lp/lib/paperclip_processors/watermark.rb:44:in `make' paperclip (4.1.1) lib/paperclip/processor.rb:33:in `make'
paperclip (4.1.1) lib/paperclip/attachment.rb:462:in `block in post_process_style'
paperclip (4.1.1) lib/paperclip/attachment.rb:461:in `post_process_style'
paperclip (4.1.1) lib/paperclip/attachment.rb:454:in `block in post_process_styles'
paperclip (4.1.1) lib/paperclip/attachment.rb:453:in `post_process_styles'
paperclip (4.1.1) lib/paperclip/attachment.rb:445:in `block (2 levels) in post_process'
activesupport (4.1.0.beta1) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.0.beta1) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.0.beta1) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.0.beta1) lib/active_support/callbacks.rb:86:in `run_callbacks'
paperclip (4.1.1) lib/paperclip/callbacks.rb:36:in `run_paperclip_callbacks'
paperclip (4.1.1) lib/paperclip/attachment.rb:443:in `block in post_process'
activesupport (4.1.0.beta1) lib/active_support/callbacks.rb:82:in `run_callbacks'
paperclip (4.1.1) lib/paperclip/callbacks.rb:36:in `run_paperclip_callbacks'
paperclip (4.1.1) lib/paperclip/attachment.rb:442:in `post_process'
paperclip (4.1.1) lib/paperclip/attachment.rb:114:in `assign'
paperclip (4.1.1) lib/paperclip/has_attached_file.rb:66:in `block in define_setter'
activerecord (4.1.0.beta1) lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
activerecord (4.1.0.beta1) lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
Voici mon modèle: - /model/asset.rb
class Asset < ActiveRecord::Base
...
belongs_to :user
belongs_to :member_visibility
has_attached_file :image,
:processors => [:watermark],
:url => "/system/:class/:attachment/:id_partition/:style/:filename",
:path => ":rails_root/public/system/:class/:attachment/:id_partition/:style/:filename",
:styles => {
:seperator => {
:geometry => '2000x1333#',
:format => 'jpg'
},
:thumb => Proc.new { |instance| instance.resize_cover_image('thumb') },
:gallery => {
:processors => [:watermark],
:geometry => Proc.new { |instance| instance.resize_cover_image('gallery') },
:watermark_path => Rails.root.join('app/assets/images/watermark.png'),
:position => 'SouthWest',
:format => 'jpg'},
:medium => {
:processors => [:watermark],
:geometry => Proc.new { |instance| instance.resize_cover_image('medium') },
:watermark_path => Rails.root.join('app/assets/images/watermarksmall.png'),
:position => 'SouthEast',
:format => 'jpg',
:quality => 80
}
},
:convert_options => {
:seperator => '-set colorspace sRGB -strip -quality 50 -sharpen 0x0.5',
:thumb => '-set colorspace sRGB -strip -quality 80',
:gallery => '-set colorspace sRGB -strip -quality 90',
:medium => '-set colorspace sRGB -strip -quality 80 -sharpen 0x0.5'
}, dependent: :allow_destroy
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
crop_attached_file :image, :aspect => :set_aspect_ratio
def resize_cover_image(style)
geo = Paperclip::Geometry.from_file(Paperclip.io_adapters.for(image))
case style
when 'thumb'
geo.horizontal? ? '350x233#' : '200x300#'
when 'medium'
geo.horizontal? ? '750x500#' : '370x555#'
when 'gallery'
geo.horizontal? ? '1125x750#' : '600x900#'
end
end
private
...
end
Remarque si je commente sur le chemin de filigrane de la galerie & moyen et comme les processeurs cela fonctionne très bien. Donc, la configuration de mon trombone est bonne.
Voici le répertoire lib/paperclip_processors/watermark.rb (selon Watermark images with paperclip, rails 4)
module Paperclip
class Watermark < Processor
# Handles watermarking of images that are uploaded.
attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :watermark_path, :watermark_offset, :overlay, :position
def initialize file, options = {}, attachment = nil
super
geometry = options[:geometry]
@file = file
@crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse geometry
@current_geometry = Geometry.from_file @file
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
@watermark_path = options[:watermark_path]
@position = options[:position].nil? ? "SouthEast" : options[:position]
@watermark_offset = options[:watermark_offset]
@overlay = options[:overlay].nil? ? true : false
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
# TODO: extend watermark
# Returns true if the +target_geometry+ is meant to crop.
def crop?
@crop
end
# Returns true if the image is meant to make use of additional convert options.
def convert_options?
not @convert_options.blank?
end
# Performs the conversion of the +file+ into a watermark. Returns the Tempfile
# that contains the new image.
def make
dst = Tempfile.new([@basename, @format].compact.join("."))
dst.binmode
if watermark_path
command = "convert"
params = %W['#{fromfile}']
params += transformation_command
params += %W['#{watermark_path}' -gravity #{@position} -composite]
params << "'#{tofile(dst)}'"
else
command = "convert"
params = ["'#{fromfile}'"]
params += transformation_command
params << "'#{tofile(dst)}'"
end
begin
Paperclip.run(command, params.join(' '))
rescue ArgumentError, Cocaine::CommandLineError
raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny
end
dst
end
def fromfile
File.expand_path(@file.path)
end
def tofile(destination)
File.expand_path(destination.path)
end
def transformation_command
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = %W[-resize '#{scale}']
trans += %W[-crop '#{crop}' +repage] if crop
trans << convert_options if convert_options?
trans
end
end
end
--- Autres choses que je remarquai:
Si je supprime le contenu de faire complètement - changer de façon à :
def font
fin
Je reçois toujours l'erreur. Si quelqu'un peut me pointer dans la bonne direction ce serait génial!
Cheers.
params =% W ['# {fromfile}'] - Pouvez-vous coller la sortie de fromfile? – tebayoso
["'\"/var/dossiers/9p/r1mdc4gn5d9gdqvtm1tcf3l80000gn/T/f3a61c06aea3a7b924f08cfb0c78c67220140619-74328-jh95u5 [0] \ "'"] –
Est-ce la sortie de fromfile ou de params? Ce – tebayoso