我正在阅读一个教程,当试图将用户添加到我的数据库时,只是想出了这个错误语句。我试图找出如何正确阅读这些错误陈述。例如,我看到输出表示语法错误,意外的tASSOC。期待keyword_end。因此,为了在发布之前尝试解决这个问题,我在user.rb文件(语句指向的那个文件)中注释了该行。但那并不奏效。由于终端输出表示“期望keyword_end”,所以我还输入了一个额外的“结束”。调试RoR语法错误
这里是确切的终端输出:
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/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in `load'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in `block in load_file'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:453:in `load_file'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:340:in `require_or_load'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:491:in `load_missing_constant'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in `each'
from /Users/zkidd/.rvm/gems/[email protected]/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in `const_missing'
from (irb):6
from /Users/zkidd/.rvm/gems/[email protected]/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start'
from /Users/zkidd/.rvm/gems/[email protected]/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start'
from /Users/zkidd/.rvm/gems/[email protected]/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+\-.][email protected][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
任何指导,将不胜感激,因为我真的不知道想从头开始重建这件事:-)
谢谢潘。 。 。我也意识到,我在第二个验证者声明中拼写错误。现在全部修好了。再次感谢。 – zkidd 2010-11-22 18:45:16