sudo -s
cd /var/discourse
./launcher enter app
rails c
u = User.create(username: "dunderhead", email: "dunderhead@live.com", password: "password")
u.activate
现在,激活步骤失败,出现以下错误:
[7] pry(main)> u.activate
ActiveRecord::RecordNotSaved: You cannot call create unless the parent is saved
from /var/www/discourse/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8/lib/active_record
/associations/collection_association.rb:342:in `_create_record
ActiveRecord::RecordInvalid: Validation failed: Password is too short (minimum is 10 characters)
from /home/robert/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/validations.rb:80:in `raise_validation_error'
在 create 后面加一个感叹号会更快地得到这个结果:
u = User.create!(username: "dunderhead", email: "dunderhead@live.com", password: "password")