Reputation: 513
I am going through a tutorial and just came up with this error statement when trying to add a user to my db. I'm trying to figure out how to properly read these error statements. For instance I see that the output says syntax error, unexpected tASSOC. expecting keyword_end. So to try to fix that before posting here, I commented out the line in my user.rb file (the one the statement is pointing too). But that did not work. I also put in an extra "end" since the terminal output said "expecting keyword_end."
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+\-.]+@[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
Any guidance would be appreciated, as I really don't want to rebuild this thing from the beginning :-)
Upvotes: 4
Views: 3687
Reputation: 34350
You are missing a comma after the :presence => true parameters:
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, :presense => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
end
Upvotes: 5
Reputation: 15736
You have some missing commas on the 2 lines preceding the syntax errors.
Upvotes: 0