我一直在處理一個問題,其中出現錯誤:「沒有將字符串隱式轉換爲數組」。沒有將字符串隱式轉換爲數組 - Rails 4.1.0.beta1
把這個放在上下文中:我在Rails 4.1.0.beta1上,我正在使用Paperclip。我正在嘗試爲我的圖像添加水印。我發現了以下解決方案:Watermark images with paperclip, rails 4
我有點在昨天晚上收到這裏說的錯誤信息之後得到了它的工作 - 然後我做了一個小小的改變,這是我沒有做的。現在我再次遇到以下錯誤?!這可能很容易,但我似乎沒有看到它。
任何幫助將不勝感激。
以下是錯誤消息:
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'
這裏是我的模型: - /model/asset.rb
注意,如果我註釋掉畫廊&介質的水印路徑以及作爲處理器它工作得很好。所以我的回形針設置都很好。
這裏的lib/paperclip_processors/watermark.rb(按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
---其他的事情,我注意到:
如果我卸妝的內容完全 - 因此將其更改爲:
DEF使
末
我仍然得到錯誤。如果任何人都可以將我指向正確的方向,那就太棒了!
乾杯。
params =%W ['#{fromfile}'] - 您可以粘貼fromfile的輸出嗎? – tebayoso
[「'\」/ var/folders/9p/r1mdc4gn5d9gdqvtm1tcf3l80000gn/T/f3a61c06aea3a7b924f08cfb0c78c67220140619-74328-jh95u5 [0] \「'」] –
這是來自fromfile或params的輸出嗎? – tebayoso