rails 3 中的重音问题

Problems with accents in rails 3

我在 rails 3

中的实例变量内部遇到重音问题

控制器

class WelcomeController < ApplicationController
  def index
    @tutor="Uriel Hernández"
  end
end

查看

<h1>Bienvenido al curso de Ruby on Rails 3</h1>
<h2>Tutor: <%=@tutor  %></h2>
<p>Esta es mi primera vista</p>

浏览器

 SyntaxError in WelcomeController#index

/home/fernando/codigofacilito/helloworld/hello_world/app/controllers/welcome_controller.rb:3: invalid multibyte char (US-ASCII)
/home/fernando/codigofacilito/helloworld/hello_world/app/controllers/welcome_controller.rb:3: invalid multibyte char (US-ASCII)
/home/fernando/codigofacilito/helloworld/hello_world/app/controllers/welcome_controller.rb:3: syntax error, unexpected $end, expecting keyword_end
    @tutor="Uriel Hernández"
                        ^
Rails.root: /home/fernando/codigofacilito/helloworld/hello_world

你 Ruby 是哪个版本 运行?

您可能需要在文件顶部指定 #encoding 指令。

参见:invalid multibyte char (US-ASCII) with Rails and Ruby 1.9