我的会议工作正常,花花公子,然后我
现在当我尝试注销时,即使重新启动计算机,也不会让我退出!我怎么知道这是因为我的导航栏有条件登录,所以如果你没有登录就会看到登录链接。我甚至尝试删除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
端
如果您需要任何其他文件,请与我们联系。
答案 0 :(得分:0)
我最终弄明白了。我刚刚改变了
cookies.delete(:remember_token)
到
cookies[:remember_token] = nil