我已经获取了名为 socialstream 的 gem 的最新代码库,但我注意到 Windows 机器上的文件上传存在问题。问题似乎与下面的代码有关...
# Monkey patches to Ruby on Rails
#
# Use unix file util to prove the content type sent by the browser
class ActionDispatch::Http::UploadedFile
def initialize_with_magic(*args, &block)
initialize_without_magic(*args, &block)
if (unix_file = `which file`.chomp).present? && File.exists?(unix_file)
`#{ unix_file } -v 2>&1` =~ /^file-(.*)$/
version = $1
@content_type =
if version >= "4.24"
`#{ unix_file } -b --mime-type #{ @tempfile.path }`.chomp
else
`#{ unix_file } -bi #{ @tempfile.path }`.chomp =~ /(\w*\/[\w+-\.]*)/
$1
end
end
end
alias_method_chain :initialize, :magic
end
错误如下
NoMethodError (undefined method
chomp' for nil:NilClass): social_stream-base (0.22.0) lib/rails/social_stream.rb:8:in
initialize_with_magic' actionpack (3.2.5) lib/action_dispatch/http/upload.rb:39:innew' actionpack (3.2.5) lib/action_dispatch/http/upload.rb:39:in
normalize_parameters' actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:inblock in normalize_parameters' actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:in
each' actionpack ( 3.2.5) lib/action_dispatch/http/parameters.rb:73:innormalize_parameters' actionpack (3.2.5) lib/action_dispatch/http/upload.rb:41:in
normalize_parameters' actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:inblock in normalize_parameters' actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:in
each' actionpack (3.2.5) lib/action_dispatch/ http/parameters.rb:73:innormalize_parameters' actionpack (3.2.5) lib/action_dispatch/http/upload.rb:41:in
normalize_parameters'
有没有办法让这个在 Windows 上工作,或者通过使用 gem,我可以在 Windows 上安装的东西,或者重写文件?