【发布时间】:2010-11-22 18:22:05
【问题描述】:
我正在阅读一个教程,但在尝试将用户添加到我的数据库时,我发现了这个错误语句。我试图弄清楚如何正确阅读这些错误语句。例如,我看到输出显示语法错误,意外 tASSOC。期待keyword_end。因此,为了在此处发布之前尝试解决此问题,我在 user.rb 文件中注释掉了该行(该语句也指向该行)。但这没有用。我还添加了一个额外的“结束”,因为终端输出说“期待关键字结束”。
这是确切的终端输出:
SyntaxError: /Users/zkidd/Sites/rails_projects/sample_app/app/models/user.rb:19: syntax error, unexpected tASSOC, expecting keyword_end
:length => { :maximum => 50 }
^
/Users/zkidd/Sites/rails_projects/sample_app/app/models/user.rb:23: syntax error, unexpected tASSOC, expecting $end
:format => { :with => email_regex },
^
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in `load'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in `block in load_file'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:453:in `load_file'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:340:in `require_or_load'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:491:in `load_missing_constant'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in `each'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in `const_missing'
from (irb):6
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start'
from /Users/zkidd/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.1/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
这是我的 user.rb 文件:
class User < ActiveRecord::Base
attr_accessible :name, :email
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true
:length => { :maximum => 50 }
validates :email, :presence => true
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
end
任何指导都将不胜感激,因为我真的不想从一开始就重建这个东西:-)
【问题讨论】:
标签: ruby-on-rails