在我的会话中注销时出现问题

[英]Trouble with log out in my session


I'm on Michael Hartl tutorial chapter 8 login and logout . I've successfully login. But the log out doesn't work .I'm staying logged in after trying to log out . The rspec when testing for the sign in button after loggout doesn't catch the error Here are the code. for

我在Michael Hartl教程第8章登录和注销。我已经成功登录了。但注销不起作用。我在尝试注销后仍然保持登录状态。在loggout之后测试登录按钮时的rspec没有捕获错误以下是代码。对于

views/layouts/header.html.erb

视图/布局/ header.html.erb

<header class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
           <%= link_to "sample app", root_path , id: "logo"%>
             <nav>
                <ul class="nav pull-right">
                    <li><%= link_to "Home", root_path %></li>
                    <li><%= link_to "Help", help_path %></li>
                    <% if signed_in? %>
                    <li><%= link_to "Users", '#' %></li>
                    <li id="fat-menu" class="dropdown">
                       <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                          Account <b class="caret"></b>
                       </a>
                         <ul class= "dropdown-menu">
                           <li><%= link_to "Profile", user_path(current_user) %></li>
                           <li><%= link_to "Settings", '#' %></li>
                           <li class="divider"></li>
                           <li>
                            <%= link_to "Sign out", signout_path, method: "delete" %>
                           </li>
                        </ul >

                    <% else %>
                    <li><%= link_to "Sign in", signin_path %></li>
                    <% end %>
                </ul>
             </nav>
        </div>
    </div>
</header>

helpers/sessions_helper.rb

助手/ sessions_helper.rb

module SessionsHelper

   def sign_in(user)
     cookies.permanent[:remember_token] = user.remember_token
     current_user = user
   end

   def signed_in?
     !current_user.nil?
   end

   def curent_user=(user)
     @current_user = user
   end

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

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

controllers/sessions_controller.rb

控制器/ sessions_controller.rb

class SessionsController < ApplicationController

  def new
  end

  def create
    user = User.find_by_email(params[:session][:email])
    if user && user.authenticate(params[:session][:password])
      sign_in user
      redirect_to user
    else
     flash.now[:error] = "Invalid email or password combination"
         render 'new'
    end
  end

  def destroy
    sign_out
    redirect_to root_path
  end
end

1 个解决方案

#1


1  

Finaly got it working with rake db:reset

最终使用rake db:reset

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/11/21/3a6a2387bbb5733d177811cb7c4a824e.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告