在将Rails从SQLite迁移到SQL Server之前,我的设计工作正常。迁移全部成功并能够登录Rails。但是,当我单击“注销”时,我得到了错误提示,
> NoMethodError in Devise::SessionsController#destroy undefined method
> `remember_created_at=' for #<User:0x00007fe169c25d10> Did you mean?
> remember_me=
Rails.root: /home/blacklight/projects/tth-blacklight
Application Trace | Framework Trace | Full Trace
activemodel (5.2.1) lib/active_model/attribute_methods.rb:430:in `method_missing'
devise (4.5.0) lib/devise/models/rememberable.rb:61:in `forget_me!'
devise (4.5.0) lib/devise/controllers/rememberable.rb:32:in `forget_me'
devise (4.5.0) lib/devise/hooks/forgetable.rb:9:in `block in <main>'
warden (1.2.7) lib/warden/hooks.rb:15:in `block in _run_callbacks'
warden (1.2.7) lib/warden/hooks.rb:10:in `each'
warden (1.2.7) lib/warden/hooks.rb:10:in `_run_callbacks'
warden (1.2.7) lib/warden/manager.rb:52:in `_run_callbacks'
warden (1.2.7) lib/warden/proxy.rb:263:in `block in logout'
db / migrate / 2018..add_devise_to users.rb
class AddDeviseToUsers < ActiveRecord::Migration[5.2]
def self.up
change_table :users do |t|
t.string :email, null: true
end
add_index :users, :email, unique: true
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end
db / Schema.rb
ActiveRecord::Schema.define(version: 2018_11_15_061838) do
create_table "bookmarks", id: :integer, force: :cascade do |t|
t.integer "user_id", null: false
t.string "user_type"
t.string "document_id"
t.string "document_type"
t.binary "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["document_id"], name: "index_bookmarks_on_document_id"
t.index ["user_id"], name: "index_bookmarks_on_user_id"
end
create_table "searches", id: :integer, force: :cascade do |t|
t.binary "query_params"
t.integer "user_id"
t.string "user_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_searches_on_user_id"
end
create_table "users", force: :cascade do |t|
t.boolean "guest", default: false
t.string "email"
t.index ["email"], name: "index_users_on_email", unique: true
end
end
不确定要看什么或在哪里看。我是Rails的新手,所以简单的说明会很有帮助。谢谢。
答案 0 :(得分:0)
我不确定迁移是否确实引起了问题,但是我了解到model / user.rb中的:rememberable 选项负责创建时间并管理 remember_created_at 。并且在登录用户时我没有记住我复选框。因此,我总共删除了:rememberable选项。并且要确保用户在一段时间后登出:timeoutable 选项
答案 1 :(得分:0)
您需要修改forget_me
中的lib / devise / models / rememberable.rb
函数。
删除或评论此行:
self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out
并添加以下行:
self.remember_me = nil if self.class.expire_all_remember_me_on_sign_out
它应该像这样:
def forget_me!
return unless persisted?
self.remember_token = nil if respond_to?(:remember_token)
self.remember_me = nil if self.class.expire_all_remember_me_on_sign_out
#self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out
save(validate: false)
end