在我的 Rails 项目中,我尝试使用设计 gem 从电子邮件登录切换到用户名登录。到目前为止,我做了所有步骤,但是当我做黄瓜时,我看到了这个输出:
Given a user "Aslak" exists
# features/step_definitions/login_steps.rb:16
unknown attribute: username (ActiveRecord::UnknownAttributeError)
./features/step_definitions/login_steps.rb:17:in `/^a user "(.*?)" exists$/'
features/login.feature:4:in `Given a user "Aslak" exists'
给定用户“Aslak” 的存在如下所示:
Given /^a user "(.*?)" exists$/ do |user_name|
@user = User.create!(:username => user_name, :password => "s3cr3t")
end
但是当我做 rails c
u = User.first
我看到这个输出:
=> #<User id: 1, email: "aslak@tamarawobben.nl", encrypted_password: "$2a$10$XjYgPtD4Ol4/sEpe934O6.yPcxs.jBF.m9SNTV.qhJp4...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 3, current_sign_in_at: "2012-11-05 20:27:44", last_sign_in_at: "2012-11-05 19:35:00", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2012-11-03 20:21:54", updated_at: "2012-11-06 07:58:36", username: "asLak">
所以在我看来,用户名是存在的。
有人知道如何解决这个问题吗?
罗洛夫