Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将可跟踪(设计)添加到现有用户模型?_Ruby On Rails_Ruby_Devise - Fatal编程技术网

Ruby on rails 将可跟踪(设计)添加到现有用户模型?

Ruby on rails 将可跟踪(设计)添加到现有用户模型?,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,问题:我之前创建了一个用户模型,其中包含最少的设计信息。我看到Desive有一个“可跟踪”系统,并希望将其实现到现有模型中。我补充说: class AddSignInCountToUsers < ActiveRecord::Migration[5.2] def change add_column :users, :sign_in_count, :integer end end 型号: NoMethodError in Devise::SessionsController#

问题:我之前创建了一个用户模型,其中包含最少的设计信息。我看到Desive有一个“可跟踪”系统,并希望将其实现到现有模型中。我补充说:

class AddSignInCountToUsers < ActiveRecord::Migration[5.2]
  def change
    add_column :users, :sign_in_count, :integer
  end
end
型号:

NoMethodError in Devise::SessionsController#create
undefined method `current_sign_in_at' for #<User:0x00007f484e5ef770>
#line with red highlight
        match ? attribute_missing(match, *args, &block) : super
NoMethodError (undefined method `current_sign_in_at' for #<User:0x00007f484e5ef770>):

activemodel (5.2.1) lib/active_model/attribute_methods.rb:430:in `method_missing'
  devise_for :users, controllers: { confirmations: 'confirmations' }
  devise :database_authenticatable, :registerable,
          :confirmable, :recoverable, :rememberable, :validatable, :trackable

        def active_for_authentication?
          super && approved
        end

        def inactive_message
          approved? ? super : :not_approved
        end
...
...
...
这是一个设计问题还是由其他地方引起的

这个问题也可能是因为现有的模型(不确定为什么这是真的,只是以防万一),因为如果是这样,我可以覆盖t并重新创建它,因为它仍在开发中


我想利用Desive提供的所有功能,并想将Desive的其余功能迁移到我的模型中。有人得到一两个建议吗?

可跟踪的
模块需要的不仅仅是
登录计数
属性。
将列出所需列的完整列表

如果为其余列添加另一个迁移,则所有操作都应按预期进行。

回答:

NoMethodError in Devise::SessionsController#create
undefined method `current_sign_in_at' for #<User:0x00007f484e5ef770>
#line with red highlight
        match ? attribute_missing(match, *args, &block) : super
NoMethodError (undefined method `current_sign_in_at' for #<User:0x00007f484e5ef770>):

activemodel (5.2.1) lib/active_model/attribute_methods.rb:430:in `method_missing'
  devise_for :users, controllers: { confirmations: 'confirmations' }
  devise :database_authenticatable, :registerable,
          :confirmable, :recoverable, :rememberable, :validatable, :trackable

        def active_for_authentication?
          super && approved
        end

        def inactive_message
          approved? ? super : :not_approved
        end
...
...
...
(不久后发现此问题:)

获得绿色支票的答案有帮助

我第一次尝试简单地添加trackable,但由于某种原因无法工作,也不会迁移(没有保存错误)

但他们第一次使用recc,例如:

rake db:migrate:down VERSION=20140126101944 # use version of the user migration
rake db:migrate up VERSION=20140126101944 # use version of the user migration
我在这次迁移中遇到的唯一问题是,我添加到users表中的所有其他迁移都没有随之迁移(名称等),因此我必须重新迁移所有内容


为了澄清这一点,正如其他人所建议的,我需要更多的专栏,而不仅仅是trackable的专栏。所以这可能是这里的全部问题。

o哇,那一定是问题所在。我最终覆盖了表(我创建了我的答案),并重新迁移了所有内容。我看到了你在迟到3分钟后的回复,哈哈。谢谢你!我会给你加1,因为这很可能是我遇到的实际问题,为什么它不起作用。