我是第一个使用 ruby 的,所以当我遵循指南(http://guides.rubyonrails.org/getting_started.html)时,我得到了如下错误:
在 2012-06-07 17:22:36 +0900 开始为 127.0.0.1 获取“/问题”
SyntaxError (/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:3: 无效的多字节字符 (US-ASCII) /Users/sookcha/Desktop/Dev/CSap/app/models/question.rb: 3: 语法错误,意外 $end,期望关键字_end 验证 :name, :presence => true ^): app/controllers/questions_controller.rb:2:in `'
渲染 /Users/sookcha/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.1ms) 渲染 /Users/sookcha/ .rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms) 渲染/Users/sookcha/.rvm/gems/ruby -1.9.3-p125/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb 在救援/布局中(10.7 毫秒)
当我刷新页面时,出现以下不同的错误:
Started GET "/questions" for 127.0.0.1 at 2012-06-07 17:22:40 +0900
NoMethodError (undefined method `key?' for nil:NilClass):
我的代码是
class Question < ActiveRecord::Base
attr_accessible :content, :name, :title
validates :name, :presence => true
validates :title, :presence => true,
:length => { :minimum => 5 }
end
我的代码有什么问题?
编辑
当我插入
# encoding: utf-8,
我的代码时,我得到了一个不同
/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:5: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' validates :name, :presence => true ^ /Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:7: syntax error, unexpected tASSOC, expecting keyword_end :length => { :minimum => 5 } ^):
的错误,比如:怎么了?