“\ xC2”从ASCII-8BIT到UTF-8

时间:2023-01-05 20:39:42

I'm trying to run a Ruby on Rails application on my Ubuntu 12.04 server. I have successfully started the Rails server, but when I open it in my browser as localhost:3000, it shows me the following error:

我正在尝试在我的Ubuntu 12.04服务器上运行Ruby on Rails应用程序。我已成功启动Rails服务器,但当我在浏览器中以localhost:3000打开它时,它显示以下错误:

Encoding::UndefinedConversionError in PagesController#index

"\xC2" from ASCII-8BIT to UTF-8
Rails.root: /home/tarun/tarun-webapp

Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:21:in `jammit'
Request

Parameters:

None
Show session dump

Show env dump

Response

Headers:

None

Here is index method of pages_controller.rb

这是pages_controller.rb的索引方法

class PagesController < ApplicationController
        layout false

  def index
        @user_session = UserSession.new
        @user = User.new
    if current_user
      redirect_to user_root_url
    end
  end

How can I resolve this error?

我该如何解决这个错误?

1 个解决方案

#1


0  

Most likely LANG=C or locale is unset.

很可能LANG = C或语言环境未设置。

Can also try something like this_should_be_a_unicode_string = this_should_be_a_unicode_string.force_encoding('UTF-8')

也可以尝试类似this_should_be_a_unicode_string = this_should_be_a_unicode_string.force_encoding('UTF-8')

http://www.ruby-doc.org/core-2.1.1/Encoding.html

http://www.ruby-doc.org/core-2.1.1/Encoding.html

#1


0  

Most likely LANG=C or locale is unset.

很可能LANG = C或语言环境未设置。

Can also try something like this_should_be_a_unicode_string = this_should_be_a_unicode_string.force_encoding('UTF-8')

也可以尝试类似this_should_be_a_unicode_string = this_should_be_a_unicode_string.force_encoding('UTF-8')

http://www.ruby-doc.org/core-2.1.1/Encoding.html

http://www.ruby-doc.org/core-2.1.1/Encoding.html