1

我的会议工作得很好,花花公子,然后我

  1. 创造了“还记得我吗?” 登录复选框
  2. 尝试添加邮件进行注册
  3. 创建了一个新用户来查看我的邮件程序是否正常工作

现在,当我尝试注销时,即使我重新启动计算机,它也不会让我注销!我怎么知道我的导航栏有登录条件,所以如果你没有登录,你会看到登录链接。我什至尝试删除 cookie,但每次刷新页面时它都会重新出现。

用户#创建

def create
  @user = User.new(params[:user])

  respond_to do |format|
    if @user.save
      UserMailer.registration_confirmation(@user).deliver
      sign_in(@user)
      format.html { redirect_to @user, notice: 'User successfully created.' }
      format.json { render json: @user, status: :created, location: @user }
    else
      format.html { render action: 'new' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

导航栏

    <nav class="clearfix">
        <% if !signed_in? %>
            <%= link_to "home", root_url %>
        <% else %>
            <%= link_to "my profile", current_user %>
            <%= link_to "edit profile", edit_user_path(current_user) %>
            <%= link_to "friends", user_friends_path(current_user) %>
        <% end %>

        <div class="rightnav">
        <% if signed_in? %>
            <%= link_to "active users", users_path %>
            <%= link_to "log out", signout_path, method: "delete", :id =>"logoutlink" %>
        <% else %>
            <%= link_to "sign up", new_user_path, :id => "signuplink" %>
            <!-- <a href="#" id="signuplink">Sign Up</a> -->
            <%= link_to "log in", signin_path, :id => "loginlink" %>
            <!-- <a href="#" id="loginlink">Log In</a> -->
        <% end %>
        </div>
    </nav>

会话控制器

class SessionsController < ApplicationController

def new
end

def create
    user = User.find_by_email(params[:session][:email])
    if user && (!params[:session][:email].blank?) && user.authenticate(params[:session][:password])
    # if params[:remember_me]
    #   cookies.permanent[:remember_token] = user.remember_token
    # else
    #   cookies[:remember_token] = user.remember_token
    # end
      sign_in user
      redirect_to user_path(user)
    else
      flash.now[:error] = "Invalid email and/or password."
      render 'new'
    end
end

def destroy
    sign_out
    redirect_to root_url
end

结尾

会话助手

module SessionsHelper

def sign_in(user)
    self.current_user = user
end

def signed_in?
    !current_user.nil?
end

def sign_out
  self.current_user = nil
  cookies.delete(:remember_token)
end

def current_user=(user)
    @current_user = user
end

def current_user
    @current_user ||= User.find_by_remember_token(cookies[:remember_token])
end

结尾

如果您需要任何其他文件,请告诉我。

4

1 回答 1

0

我最终想通了。我刚变

cookies.delete(:remember_token)

cookies[:remember_token] = nil

于 2012-10-23T18:59:14.107 回答