ruby魔法编码不起作用

时间:2012-02-20 01:12:01

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

我有一个rails应用程序,我一直收到此错误

  /srv/projects/app/controllers/application_controller.rb:174: invalid multibyte char (US-ASCII) /srv/projects/app/controllers/application_controller.rb:174: invalid multibyte char (US-ASCII) /srv/projects/app/controllers/application_controller.rb:174: syntax error, unexpected $end, expecting ')' ...e_title = h("#{project_name} — #{name || translate_locatio... ... ^

并且修复应该是here但是当我在我的应用程序控制器上添加该行时,我仍然会收到错误...我甚至重新启动了apache

这是我的应用程序控制器

# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

# encoding: utf-8


class ApplicationController < ActionController::Base
# encoding: utf-8

2 个答案:

答案 0 :(得分:2)

编码注释必须先于文件顶部 - 包括其他注释(如果有的话,除了shebang)。

答案 1 :(得分:1)

你的课应该是这样的:

# encoding: utf-8
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base

(顶部有魔术评论)