Rails - US-ASCII中的无效字节序列

时间:2013-08-27 14:08:41

标签: ruby-on-rails-3 character-encoding compatibility

我失去了所有的头发:

我的rails服务器启动正常,但无论对它的请求是什么(资产和公共内容除外),我都会收到此错误:

ArgumentError in HomeController#index

invalid byte sequence in US-ASCII

使用此框架跟踪(无应用程序跟踪)

better_errors (0.9.0) lib/better_errors/stack_frame.rb:19:in `from_exception'
better_errors (0.9.0) lib/better_errors/error_page.rb:52:in `backtrace_frames'
better_errors (0.9.0) lib/better_errors/middleware.rb:114:in `log_exception'
better_errors (0.9.0) lib/better_errors/middleware.rb:87:in `rescue in protected_app_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/home/augustin/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/augustin/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/augustin/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

我的团队在Windows上工作,它在他们的平台上工作正常,但是在ubuntu的计算机上发生了这个错误。到目前为止一切正常,如果我回滚到我的最新提交它再次工作,所以错误在合并中。

问题是:

  • 如何调试此问题,因为它不是真的很冗长?
  • 错误究竟意味着什么? Ascii是预期的,那不是我们所拥有的,或者ascii被发现并且这不是预期的结果?
  • 错误更可能是在应用程序控制器中的gem中吗?
  • 有没有办法过滤所有特殊字符以了解它来自哪里?
  • 有哪些其他信息可以帮助我调试这个?

读数:

附:

Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.13'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

# Database
gem 'pg'

# Database Init
gem 'seed_dump'
# gem "seedbank"

# gem 'active_model_serializers'

# HAML
gem 'haml', '4.0.3'
gem 'html2haml'

# Front-end
gem 'jquery-rails'
gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git', :branch => '3'
# gem 'font-awesome-sass-rails'
gem 'font-awesome-rails'
gem 'bootstrap-datepicker-rails'
gem 'jquery-tokeninput-rails' # tag and autocomplete for conversation

# Shared mustache templates for rails 3.
gem 'smt_rails'

# Attachements
gem 'paperclip', '3.4.2'

# Share on Social Network
gem 'social-share-button'

# Jquery Upload File
# gem "jquery.fileupload-rails"
# Map
gem 'mapbox-rails', :git => 'https://github.com/aug-riedinger/mapbox-rails.git'
gem 'leaflet-markercluster-rails'

# Authentication
gem 'bcrypt-ruby', '3.0.1', :require => 'bcrypt'
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook', "1.4.0"
gem 'oauth2'
gem 'fb_graph'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'coffee-script-source', '1.5.0'    
  gem 'uglifier', '>= 1.0.3'
end

group :development, :test do
  gem 'better_errors'
  gem 'binding_of_caller'
end

platforms :ruby do
  group :development, :test do
    gem 'railroady'
  end
  group :production do
    gem 'aws-sdk'
    gem 'unicorn'
    gem 'newrelic_rpm'
  end
end

# Messaging - Notifications
gem 'simple_form'
gem 'mailboxer'
gem 'pusher'

gem 'amistad'

# Pdf generation
gem 'prawn'
gem 'prawnto'

# Payments
gem 'activemerchant'

# SEO
gem 'dynamic_sitemaps'
gem 'metamagic'

# Static files
gem 'markdown-rails'

感谢帮助一个狡猾的家伙...

1 个答案:

答案 0 :(得分:5)

所以,我终于通过查看历史记录中的每个提交(git log),测试并最终制作git diff <commit_hash> <previous_commit_hash>以查看更改内容来找到解决方案。

我在帮助器中有非ASCII字符(显然在每次调用时加载):

  def group_currency(group)
    currency = group.currency
    case currency 
    when 'EUR'
      haml_tag "€"
    when 'USD'  
      haml_tag "$"
    when 'GBP'
      haml_tag "£"   
    end

  end 

因此,在文件的开头添加它可以解决它:

#encoding: utf-8
module GroupsHelper
...

但我发现更多问题是为什么Rails无法在日志中找到并报告引发问题的文件... 我在Rails上为此创建了一个问题:https://github.com/rails/rails/issues/12041