gpt4 book ai didi

ruby-on-rails - 我收到错误语法错误,意外的$end,期待keyword_end

转载 作者:行者123 更新时间:2023-12-02 09:39:38 24 4
gpt4 key购买 nike

我是第一个使用 ruby​​ 的人,所以当我遵循指南(http://guides.rubyonrails.org/getting_started.html)时,我收到了如下错误:

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: 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 `'

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)

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

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 } ^):

怎么了?

最佳答案

有一个non-breaking space在您的代码中:

validates :name,  :presence => true
^
here

关于ruby-on-rails - 我收到错误语法错误,意外的$end,期待keyword_end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10928310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com