Debug RoR syntax error

I am looking through a tutorial and just came up with this error expression when trying to add a user to my db. I am trying to figure out how to read these error statements correctly. For example, I see that the output says a syntax error, unexpected tASSOC. awaiting a keyword. Therefore, in order to try to fix this before publishing here, I commented out a line in the user.rb file (the one that the statement indicates). But that did not work. I also added an extra โ€œendโ€ as the terminal output said โ€œkeyword pendingโ€.

Here is the exact terminal output:

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

And here is my user.rb file:

  class User < ActiveRecord::Base attr_accessible :name, :email email_regex = /\A[\w+\-.] +@ [az\d\-.]+\.[az]+\z/i validates :name, :presence => true :length => { :maximum => 50 } validates :email, :presence => true :format => { :with => email_regex }, :uniqueness => { :case_sensitive => false } end 

Any guidance would be appreciated as I really don't want to rebuild this thing from the start :-)

+4
source share
2 answers

You are missing a comma after: having => true parameters:

 class User < ActiveRecord::Base attr_accessible :name, :email email_regex = /\A[\w+\-.] +@ [az\d\-.]+\.[az]+\z/i validates :name, :presence => true, :length => { :maximum => 50 } validates :email, :presense => true, :format => { :with => email_regex }, :uniqueness => { :case_sensitive => false } end 
+5
source

You have missing commas in two lines preceding syntax errors.

0
source

All Articles