[英]Ruby on Rails Tutorial Chapter 6.3.4
創建用戶帳戶時,收到此警告。 這條消息是什么意思?
SyntaxError: /Users/KOSUKE/workspace/score_share/app/models/user.rb:6: syntax error, unexpected ':', expecting keyword_end format: { with: VALID_EMAIL_REGEX } ^ /Users/KOSUKE/workspace/score_share/app/models/user.rb:7: syntax error, unexpected ':', expecting keyword_end uniqueness: { case_sensitive: false } ^ from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:457:in `load' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:457:in `block in load_file' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:647:in `new_constants_in' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:456:in `load_file' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:354:in `require_or_load' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:494:in `load_missing_constant' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:184:in `const_missing' from (irb):1 from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/console.rb:110:in `start' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/console.rb:9:in `start' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:68:in `console' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `block in require' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require' from /Users/KOSUKE/workspace/score_share/bin/rails:9:in `<top (required)>' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency' from /Users/KOSUKE/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load' from /Users/KOSUKE/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Users/KOSUKE/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from -e:1:in `<main>'2.2.1 :002 >
確保您的user.rb文件看起來完全像這樣:
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
has_secure_password
validates :password, presence: true, length: { minimum: 6 }
end
該錯誤消息告訴您, user.rb
包含語法錯誤:
SyntaxError: /app/models/user.rb:6: syntax error, unexpected ':', expecting keyword_end
format: { with: VALID_EMAIL_REGEX }
^
/app/models/user.rb:7: syntax error, unexpected ':', expecting keyword_end
uniqueness: { case_sensitive: false }
你可能只是錯過了一個,
或關閉}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.