Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 Rails/Deviate:自动登录后执行操作_Ruby On Rails_Ruby On Rails 3_Devise - Fatal编程技术网

Ruby on rails Rails/Deviate:自动登录后执行操作

Ruby on rails Rails/Deviate:自动登录后执行操作,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,编辑:我使用Desive 3.4.1,但“记住后”不可用。请应用或使用2014/11/09之后发布的更新版本 好的,所以我对Rails环境相当陌生,我觉得我遗漏了一些东西 我希望在登录后执行特定的操作,无论是从表单登录还是自动登录 我发现,在“常规”登录后,在“路径”中执行“签名”。我已经在我的应用程序控制器中使用了它 class ApplicationController < ActionController::Base […] def after_sign_in_path_for(

编辑:我使用Desive 3.4.1,但“记住后”不可用。请应用或使用2014/11/09之后发布的更新版本

好的,所以我对Rails环境相当陌生,我觉得我遗漏了一些东西

我希望在登录后执行特定的操作,无论是从表单登录还是自动登录

我发现,在“常规”登录后,在“路径”中执行“签名”。我已经在我的应用程序控制器中使用了它

class ApplicationController < ActionController::Base

[…]

def after_sign_in_path_for(resource)
    myAction
end
class ApplicationController
但是,当用户通过Desive Memory选项登录时,似乎不会调用此方法

我发现这是在用户自动登录后执行的,但我不知道如何使用它。我不想仅仅为了将我的操作添加到方法中而修改Desive gem,以下内容似乎不起作用:

class ApplicationController < ActionController::Base

[…]

def after_remembered()
    myAction
end
class ApplicationController
我在这里不知所措。要么我不知道如何在记住后使用,要么我看错了方向,有另一个解决方案(如果它同时包含这两种情况,或者只包含“记住我”自动登录的情况,对我来说没问题)。有人有办法让它工作吗


PS:我正在开发一个我自己还没有开发的应用程序。如果您觉得需要更多代码才能回答,请告诉我,我将编辑我的帖子。

这是
可记忆模块的一部分,因此它属于您的模型。。。假设您的资源是
用户
您使用它的方式是

class User < ActiveRecord::Base

  devise :rememberable

  def after_remembered
    # (your code here)
  end

end
然后在应用程序中_controller.rb

class ApplicationController < ActionController::Base

  before_action :handle_sign_in_via_rememberable

  def handle_sign_in_via_rememberable
    if current_user and current_user.signed_in_via_remember?
      current_user.update_attribute(:signed_in_via_remember, false)    
      after_sign_in_path_for(User)
    end
  end

  def after_sign_in_path_for(resource)
    myAction
  end

end
class ApplicationController

有些人可能有一个更简洁的解决方案。

记忆后似乎是一个类似于行动后的回调。尝试使用是这样的:
after_membered:my_method
然后在控制器中:
def method end
我发现我使用的是Rails 3和Desive 3.4.1,所以我不能使用after_membered方法,除非我在Github上用源代码更新Desive。我看了,它真的很小,所以我只是应用了它,然后尝试了你的第一个代码,它工作了。毕竟不需要ApplicationController。一个音符,是在你记住之后
class ApplicationController < ActionController::Base

  before_action :handle_sign_in_via_rememberable

  def handle_sign_in_via_rememberable
    if current_user and current_user.signed_in_via_remember?
      current_user.update_attribute(:signed_in_via_remember, false)    
      after_sign_in_path_for(User)
    end
  end

  def after_sign_in_path_for(resource)
    myAction
  end

end