Ruby on rails Rails记住我的功能只需记住

Ruby on rails Rails记住我的功能只需记住,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,如果只是简单登录,我的记忆功能仍将创建一个永久cookie。我遵循了以下教程:http://railscasts.com/episodes/274-remember-me-reset-password 这是我的 会话控制器 class SessionsController < ApplicationController def new if current_customer redirect_to current_customer end end

如果只是简单登录,我的记忆功能仍将创建一个永久cookie。我遵循了以下教程:http://railscasts.com/episodes/274-remember-me-reset-password

这是我的

会话控制器

class SessionsController < ApplicationController
  def new
    if current_customer
        redirect_to current_customer
    end
  end
  def create
    customer = Customer.find_by_email(params[:email])
        if customer && customer.authenticate(params[:password])
        if params[:remember_me]
        cookies.permanent[:auth_token] = customer.auth_token
        else
        cookies[:auth_token] = customer.auth_token
        end
            redirect_to customer, :notice => "Logged in!"
        else
            flash.now.alert = "Invalid email or password"
            render "new"
        end
  end

  def destroy
    cookies.delete(:auth_token)
    redirect_to root_url, :notice => "Logged out!"
  end
end
class ApplicationController < ActionController::Base
  protect_from_forgery

  force_ssl

  private

    def authorize
        redirect_to login_url, alert: "Not authorized" if current_customer.nil?
    end

    def current_customer
      @current_customer ||= Customer.find_by_auth_token(cookies[:auth_token]) if cookies[:auth_token]
    end
    helper_method :current_customer
end
class sessioncontroller“已登录!”
其他的
flash.now.alert=“无效的电子邮件或密码”
呈现“新”
结束
结束
def销毁
cookies.delete(:auth_令牌)
将\u重定向到root\u url,:notice=>“已注销!”
结束
结束
应用程序控制器

class SessionsController < ApplicationController
  def new
    if current_customer
        redirect_to current_customer
    end
  end
  def create
    customer = Customer.find_by_email(params[:email])
        if customer && customer.authenticate(params[:password])
        if params[:remember_me]
        cookies.permanent[:auth_token] = customer.auth_token
        else
        cookies[:auth_token] = customer.auth_token
        end
            redirect_to customer, :notice => "Logged in!"
        else
            flash.now.alert = "Invalid email or password"
            render "new"
        end
  end

  def destroy
    cookies.delete(:auth_token)
    redirect_to root_url, :notice => "Logged out!"
  end
end
class ApplicationController < ActionController::Base
  protect_from_forgery

  force_ssl

  private

    def authorize
        redirect_to login_url, alert: "Not authorized" if current_customer.nil?
    end

    def current_customer
      @current_customer ||= Customer.find_by_auth_token(cookies[:auth_token]) if cookies[:auth_token]
    end
    helper_method :current_customer
end
class ApplicationController

我正在考虑添加一个delete,如果params没有被选中,以确保没有其他cookie存在。但是这似乎不起作用

也许你应该调用类顶部的helper\u方法调用。

尝试添加

  reset_session

来摧毁你的行动

我有一个放置助手的方法:当前的客户在班上名列前茅,但cookies似乎仍然记得它。