Inkompatible Zeichenkodierungen: ASCII-8BIT und UTF-8
Verwende ich Ruby 1.9.2 und Rails 3.0.5
Habe ich die folgende Fehlermeldung:
inkompatible Zeichenkodierungen: ASCII-8-BIT und UTF-8
Es hat nichts zu tun mit der Datenbank, denke ich.
Den Fehler happinging auf dieser Linie in einer Ansicht (nur ein div-haml call):
#content
full stack:
ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8):
21: -flash.each do |name, msg|
22: =content_tag :div, msg, :id => "flash_#{name}"
23: %div.clear
24: #content
25: = yield
26: = render :partial => "layouts/grid_right" if render_grid_right?
27: = render :partial => "layouts/footer"
app/views/layouts/application.html.haml:24:in `_app_views_layouts_application_html_haml___4380000789490545718_2180251300_2717546578298801795'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/layouts.rb:80:in `_render_layout'
actionpack (3.0.5) lib/action_view/render/rendering.rb:62:in `block in _render_template'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.5) lib/action_view/render/rendering.rb:26:in `render'
haml (3.0.25) lib/haml/helpers/action_view_mods.rb:13:in `render_with_haml'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/michaelkoper/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.5) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.5) lib/action_controller/metal/mime_responds.rb:261:in `block in retrieve_response_from_mimes'
actionpack (3.0.5) lib/action_controller/metal/mime_responds.rb:192:in `call'
actionpack (3.0.5) lib/action_controller/metal/mime_responds.rb:192:in `respond_to'
app/controllers/home_controller.rb:9:in `index'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.5) lib/active_support/callbacks.rb:445:in `_run__3968431659371141392__process_action__3163094469870857953__callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.5) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:492:in `call'
haml (3.0.25) lib/sass/plugin/rack.rb:41:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.5) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.5) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.5) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.5) lib/rails/application.rb:168:in `call'
railties (3.0.5) lib/rails/application.rb:77:in `method_missing'
railties (3.0.5) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/chunked.rb:15:in `call'
rack (1.2.1) lib/rack/handler/mongrel.rb:67:in `process'
mongrel (1.2.0.pre2) lib/mongrel.rb:165:in `block in process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `each'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:291:in `block (2 levels) in run'
Meinen gems:
Using rake (0.8.7)
Using RedCloth (4.2.2)
Using abstract (1.0.0)
Using activesupport (3.0.5)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.5)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.7)
Using tzinfo (0.3.24)
Using actionpack (3.0.5)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.15)
Using actionmailer (3.0.5)
Using arel (2.0.9)
Using activerecord (3.0.5)
Using activeresource (3.0.5)
Using authlogic (2.1.6)
Using xml-simple (1.0.14)
Using aws-s3 (0.6.2)
Using block_helpers (0.3.3)
Using bundler (1.0.10)
Using diff-lcs (1.1.2)
Using json (1.4.6)
Using gherkin (2.3.4)
Using term-ansicolor (1.0.5)
Using cucumber (0.10.0)
Using cucumber-rails (0.3.2)
Using daemons (1.0.10)
Using database_cleaner (0.6.5)
Using factory_girl (1.3.3)
Using faker (0.9.5)
Using formtastic (1.2.3)
Using gem_plugin (0.2.3)
Using haml (3.0.25)
Using thor (0.14.6)
Using railties (3.0.5)
Using rails (3.0.5)
Using kaminari (0.10.4)
Using mongrel (1.2.0.pre2)
Using mysql2 (0.2.6)
Using nokogiri (1.4.4)
Using paperclip (2.3.8)
Using rspec-core (2.5.1)
Using rspec-expectations (2.5.0)
Using rspec-mocks (2.5.0)
Using rspec (2.5.0)
Using yard (0.6.4)
Using pickle (0.4.4)
Using populator (1.0.0)
Using rspec-rails (2.5.0)
Using webrat (0.7.3)
Kommentar zu dem Problem - Öffnen
Ist Ihre Anwendung mit 'UTF-8' oder 'ASCII-8-BIT', wie der Standard-Kodierung. Auch, erhalten Sie diesen Fehler, wenn Sie keine flash-Nachrichten?
Ich löste es so: stackoverflow.com/questions/11478316/...
Einfach mal einen Kommentar: ich bearbeitet habe eine Datei mit TextEdit, und es verändert ==>'<== ein ==>`<== : es warf dann den Fehler zu finden. Glaube nicht, verwenden Sie TextEdit den Haufen Müll
InformationsquelleAutor der Frage Michael Koper | 2011-03-12
Du musst angemeldet sein, um einen Kommentar abzugeben.
Habe ich den Verdacht, dass Sie entweder mit copy/Paste einen Teil Ihrer Haml-template in die Datei, oder Sie arbeiten mit einer nicht-Unicode/non-UTF-8-freundlichen editor.
Sehen, wenn Sie können neu erstellen, die Datei von der Pike auf in einer UTF-8-freundlich-editor. Es gibt viele für jede Plattform und sehen, ob dies Ihr problem behebt. Starten Sie durch löschen der Zeile mit
#content
und Sie es manuell.InformationsquelleAutor der Antwort Vladimir Gurovich
Ich löste es, indem Sie die folgenden Schritte:
config.encoding = "utf-8"
ist in der Anwendung.rb-Datei.# encoding: utf-8
am Anfang der Datei mit UTF-8-Zeichen.Oberhalb der
<App Name>::Application.initialize!
Linie in der Umwelt.rb-Datei, fügen Sie folgende zwei Zeilen ein:http://rorguide.blogspot.com/2011/06/incompatible-character-encodings-ascii.html
InformationsquelleAutor der Antwort Ritesh Kumar
Versuchen zu finden, die genaue Linie, die dieses problem verursacht und dann die Durchsetzung UTF8-Codierung, diese Lösung funktionierte für mich.
InformationsquelleAutor der Antwort mfq
ASCII-8BIT ist Ruby ' s Beschreibung für Zeichen, die über die normale 0-0x7f ASCII-Zeichensatz, und die single-byte-Zeichen. Normalerweise wäre so etwas wie ISO-8859-1, oder eines seiner Geschwister.
Wenn Sie identifizieren können, mit welchem Charakter ist das problem verursacht, dann können Sie sagen, Ruby 1.9.2 konvertieren zwischen den Zeichensatz, die Zeichen auf UTF-8.
James Grau schrieb Serie von blogs reden über diese Art von Problemen und wie man mit Ihnen umgeht. Ich würde empfehlen, gehen durch Sie hindurch.
Dass in der Regel passiert das, weil Sie versuchen, um zwei strings zu verketten, und ein Zeichen enthält, dass nicht die Karte, um die Zeichen der anderen Zeichenfolge. Es gibt Zeichen, die in ISO-8859-1, die keine Entsprechungen in UTF-8, und Umgekehrt, und wie zu handhaben string Beitritt mit diesen Inkompatibilitäten erfordert die Programmierer, um Schritt in.
InformationsquelleAutor der Antwort the Tin Man
Ich installiert Juwel Paket mysql2.
und dann änderte ich den adapter mysql2 Datenbank.yml.
InformationsquelleAutor der Antwort StandDuPp
Für Haml setzen eine Kodierung Hinweis:
Links oben auf der Haml Seite.
InformationsquelleAutor der Antwort umitka
können Sie erzwingen, UTF8 mit
force_encoding(Encoding::UTF_8)
:Beispiel:
InformationsquelleAutor der Antwort Daniel Loureiro
Das problem war die Nutzung fehlerhafter Zitate rund um die iOS version. Stellen Sie sicher, dass alle deine Zitate sind 'und nicht' oder '.
https://github.com/CocoaPods/CocoaPods/issues/829
InformationsquelleAutor der Antwort Yllow
Ich erlebt habe ähnliches problem. Ich hatte zwar UTF-8-Codierungen gelöst (mit mysql2 und Codierung.default_external = Encoding::UTF_8 ...) inkompatible Zeichensätze: UTF-8 und ASCII-8BIT entstanden, wenn ich falsch Helfer Parameter z.B.
f.button :submit, "Zrušiť"
- funktioniert perfekt, aberf.button "Zrušiť"
- wirft-encoding-Fehler.InformationsquelleAutor der Antwort remo
Traf ich den Fehler beim migrieren einer Anwendung von Ruby 1.8.7, 1.9.3 und es nur kurzzeitig in der Produktion. Es stellte sich heraus, dass ich hatte ein paar Reste in meinem Memcache speichern. Die jetzt encoding empfindlich Ruby 1.9.3 version meiner app versucht zu mischen, alte ASCII-8BIT Werte mit neuen UTF-8.
War es so einfach wie das leeren des cache beheben Sie es für mich.
InformationsquelleAutor der Antwort carp
Verhindern ein Fehler "can' T modify frozen string" für die Codierung eine Variable, die Sie verwenden können:
var.dup.force_encoding(Encoding::ASCII_8BIT)
odervar.dup.force_encoding(Encoding::UTF_8)
InformationsquelleAutor der Antwort DarkAiR
Ich hatte ein ähnliches Problem auf einem benutzerdefinierten CoffeeScript-Datei. Ich löste es, indem Sie die endline der Codierung von "Unix/Linux" , "Mac OS Classic"
InformationsquelleAutor der Antwort Sidhannowe
Erstellung von pdf-Dokumenten mit der
rails-latex-gem
führen zu einem ähnlichen problem.Ich löste dies durch eine änderung
layouts/application.pdf.erb
zuInformationsquelleAutor der Antwort hartmut
es ist sehr seltsam, dass ich traf dieses problem nicht, da ich vergaß, geben Sie den parameter 'Typ'. z.B.:
werden sollten:
InformationsquelleAutor der Antwort Siwei Shen申思维
Nur für das Protokoll: für mich stellte sich heraus, dass es war das Juwel namens 'mysql' ... offensichtlich ist das arbeiten mit US-ASCII 8-bit - standardmäßig. So ändern Sie den Edelstein genannt mysql2 (die 2 ist der wichtige Punkt hier) löste alle meine Probleme.
Schaute ich @ die gem-Liste oben gepostet - Michael Koper hat offensichtlich mysql2 installiert, aber ich habe dies geschrieben, im Falle, jemand hat das Problem auch .. (hat mich einige Zeit, um herauszufinden,).
Wenn Sie mögen diese Antwort bitte Kommentar, und ich werde es löschen.
P. S: Deutsche Umlaute (ä,ö und ü) verschraubt es mit mysql
InformationsquelleAutor der Antwort Langusten Gustel
Ich hatte das gleiche problem beim Parsen von CSV-Dateien auf Ruby 1.9.2, die waren richtig analysiert wird, die auf Ruby 1.8. Ich fand die Antwort hier. Beim öffnen der CSV-Datei mit Ruby CSV-Moduls ist es notwendig, geben Sie die UTF-8-enconding wie folgt:
InformationsquelleAutor der Antwort Eduardo
ich hatte ein ähnliches problem und das gem-string-Peeling automatisch fixiert es für mich. https://github.com/hsbt/string-scrub , Wenn die angegebene Zeichenfolge enthält eine ungültige byte-Reihenfolge, dann, dass ungültige byte-Sequenz wird durch das unicode-Ersatzzeichen (�) und eine neue string wird zurückgegeben.
InformationsquelleAutor der Antwort dabobert
Bekam ich die gleiche kryptische Fehlermeldung von Rails 4.1, Ruby 2.3.3 in einem aktuellen Projekt, stacktrace mit Ursprung in der layout-Anwendung.html-Code.haml
Nach einem wild-goose chase, der Täter war ein UTF-8-Zeichen, die vor kurzem Hinzugefügt worden, um die Fußzeile aller Seiten. Aus irgendeinem seltsamen Grund, der Fehler würde nur zeigen, bis zeitweise.
Austausch der UTF-8-Zeichen mit dem entsprechenden HTML-escape-Sequenz
&#xHHHH;
das Problem gelöst.Ich hoffe das erspart anderen Leuten einige Zeit in der Zukunft..
InformationsquelleAutor der Antwort Tilo