2015-04-23 27 views
0

ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT): app/controllers/posts_controller.rb:27:in `new'不兼容的字符編碼:UTF-8和ASCII-8BIT在渲染動作

# GET /posts/new 
    def new 
    if params[:post] 
     @post = Post.new(post_params).dup 
     if @post.valid? 
     render :action => "confirm" 
     else 
     format.html { render action: 'new' } 
     format.json { render json: @post.errors, status: :unprocessable_entity } 
     end 
    else 
     @post = Post.new 
     @document = Document.new 
     @documents = @post.documents.all 
     @document = @post.documents.build 
    end 

我不知道爲什麼它正在發生。

+0

? –

回答

0
  • 確保config.encoding = "utf-8"有在application.rb中文件。
  • 確保您使用的'mysql2' gem代替mysql gem
  • 上耙文件的頂部把# encoding: utf-8
  • 以上的environment.rb文件Rails.application.initialize!行中,添加以下兩行:

    Encoding.default_external =編碼:: UTF_8

    Encoding.default_internal =編碼:: UTF_8

從這裏的解決方案:http://rorguide.blogspot.in/2011/06/incompatible-character-encodings-ascii.html

如果上述解決方案沒有幫助t如果我認爲你要將你的Haml模板的一部分複製/粘貼到文件中,或者你正在使用非Unicode /非UTF-8友好編輯器。

如果您可以在UTF-8友好編輯器中從頭開始重新創建該文件。有很多適用於任何平臺,看看這是否能解決您的問題。

有時你可能會得到這樣的錯誤:

incompatible character encodings: ASCII-8BIT and UTF-8

這通常是因爲你試圖連接兩個字符串,以及一個包含不映射到另一個字符串的字符集的字符。 ISO-8859-1中的字符在UTF-8中沒有等效字符,反之亦然,如何處理與那些不兼容性字符串的連接需要程序員插入。

+0

是崇高的非UTF-8友好的編輯器嗎? –

+0

@ShionYamaguchi:Sublime是流行編輯。您也可以根據您的要求自定義其設置。您可以設置'UTF-8'或首選爲默認編碼[請點擊此處](http://superuser.com/questions/581553/sublime-text-2-encoding-utf-8) –

+2

嘗試所有這些,並仍然得到錯誤。我正在使用MongoDB而不是mysql。 – jdog

0

我正在升級我的導軌和spree和錯誤實際上是從緩存中

刪除緩存來解決了這個問題對我來說

rm -rf tmp/cache 
您使用的數據庫,其寶石
相關問題