长话短说,我决定在我的本地主机上清除我的数据库,并在我的 Rails 应用程序中试验 posgreSQL 和 pgAdmin。我首先通过 pgAdmin 删除了我拥有的所有服务器。然后我跑了db:create:all
,db:migrate
最后db:test:prepare
。现在,每当我在进行所有这些数据库实验之前运行我以前的规范测试时,我的大多数测试都失败了,给了我这个错误..
Failure/Error: @user = FactoryGirl.create(:user)
NoMethodError:
undefined method `password_reset_sent_at' for #<User:0xb48a55c>
或者
Failure/Error: @user.save
NoMethodError:
undefined method `password_reset_sent_at' for #<User:0xaa9c040>
我以为我可能不允许password_reset_sent_at
作为不可访问属性,但它是可访问的,并且我的用户模型具有has_one :user_reset_password, :dependent => :destroy
.
我的 database.yml 看起来像...
development:
adapter: postgresql
encoding: unicode
database: template_development
host: localhost
pool: 5
username: jason
password: password
test:
adapter: postgresql
encoding: unicode
database: template_test
host: localhost
pool: 5
username: jason
password: password
当我运行应用程序并创建新用户时,我收到此错误。
undefined method `password_reset_sent_at' for #<User:0xa6fb184>
app/models/user.rb:78:in `empty_password_reset_token'
app/controllers/users_controller.rb:25:in `create'
empty_password_reset_token
方法是
def empty_password_reset_token
if self.password_digest_changed?
if self.password_reset_sent_at && self.password_reset_sent_at < 2.hours.ago
false
else
self.password_reset_token = ""
self.password_reset_sent_at = ""
end
end
end
我的架构文件
ActiveRecord::Schema.define(:version => 20130124193639) do
create_table "user_login_failures", :force => true do |t|
t.integer "user_id"
t.integer "login_failure_attempts"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_reset_passwords", :force => true do |t|
t.integer "user_id"
t.string "password_reset_token"
t.datetime "password_reset_sent_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password_digest"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
end
我真的不知道为什么这不起作用。这些表都有适当的列,没有任何遗漏。任何帮助,将不胜感激。