2010-11-22 8 views
4

私はチュートリアルを行っていますが、私のdbにユーザを追加しようとすると、このエラー文が出てきました。私はこれらのエラーステートメントを正しく読む方法を理解しようとしています。たとえば、出力には構文エラー、予期しないtASSOCがあることがわかります。 keyword_endが必要です。だから、ここに投稿する前にそれを修正しようとすると、私はuser.rbファイルの行をコメントアウトしました(ステートメントも指しています)。しかし、それはうまくいかなかった。私はまた、端末の出力が "keyword_endを期待している"と言っていたので、余分な "end"を入れました。ここでRoRの構文エラーをデバッグする

は、正確なターミナル出力です:

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 

私は本当にないとして任意のガイダンスは、いただければ幸いです。

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ファイルです最初からこのことを再構築したい:

答えて

5

:存在を=>真のパラメータ:

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, :presense => true, 
      :format => { :with => email_regex }, 
      :uniqueness => { :case_sensitive => false } 
end 
+0

はあなたにパンをありがとうございました。 。 。私はまた、2番目のバリデーター・ステートメントでプレゼンスが間違っていることに気付きました。すべて確定しました。再度、感謝します。 – zkidd

+0

ありがとう、私もカンマがいくつかあり、スペルミスや余分な結腸がありました。 cmdのプロンプトのエラーは混雑していて、レールが原因であると思っているのに注意していますが、代わりに誤植でした。 :) – noobcode

0

2行にカンマがいくつかある構文エラーを訂正します。あなたは後にカンマが含まれていない