我收到错误语法错误,意外的 $end,期望关键字_end [英] I got the error syntax error, unexpected $end, expecting keyword_end

查看:60
本文介绍了我收到错误语法错误,意外的 $end,期望关键字_end的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一个使用 ruby​​ 的,所以当我按照指南 (http://guides.rubyonrails.org/getting_started.html) 操作时,我得到了如下错误:

I'm first to ruby, so when i following the Guide(http://guides.rubyonrails.org/getting_started.html) I got the error like:

在 2012-06-07 17:22:36 +0900 开始为 127.0.0.1 获取/questions"

Started GET "/questions" for 127.0.0.1 at 2012-06-07 17:22:36 +0900

SyntaxError (/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:3: 无效的多字节字符 (US-ASCII)/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:3:语法错误,意外的$end,期待keyword_end验证 :name, :presence => true^):app/controllers/questions_controller.rb:2:in `'

SyntaxError (/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:3: invalid multibyte char (US-ASCII) /Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:3: syntax error, unexpected $end, expecting keyword_end   validates :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.7ms)

Rendered /Users/sookcha/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.1ms) Rendered /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) Rendered /Users/sookcha/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (10.7ms)

当我刷新页面时,出现以下不同的错误:

when I refresh the page, i got a different error below:

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

我的代码有什么问题?

What's wrong with my code?

编辑

当我插入时# encoding: utf-8, 在我的代码中,我得到了一个不同的错误,如:<代码>/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:5: 语法错误,意外的 tSYMBEG,需要关键字_do 或 '{' 或 '(' 验证 :name, :presence => true ^/Users/sookcha/Desktop/Dev/CSap/app/models/question.rb:7: 语法错误,意外的 tASSOC,期望 keyword_end :length => { :minimum => 5 } ^):
怎么了?

When I insert # encoding: utf-8, in my code, I got a different error like: /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 } ^):
What's wrong?

推荐答案

有一个非中断空间 在您的代码中:

There's a non-breaking space in your code:

validates :name,  :presence => true
                ^
               here

这篇关于我收到错误语法错误,意外的 $end,期望关键字_end的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆