我希望你能帮助,一直在努力与此一段时间: 即时通讯使用设计和Rails 3Rails 3设计会话有价值,但如果user_signed_in <<%? %>是虚假的
当我点击登录,我得到设计登录页面,我冲入用户名和密码,然后单击登录。
当我点击登录后,我被重定向到主页面,但现在我仍然看到登录链接,这意味着<%if user_signed_in? %>仍然是错误的。但是,我登录后,似乎会话变量中有一些值,这里发生了什么?我一直在使用设计一段时间,并没有任何问题。谢谢你们!
之前,我登录时所用色器件我登录与色器件
<%= session %>
_csrf_tokenAMUwVLu6G6rWfKICB43PYApFsYFRjVyJDSc2oU88uEk=warden.user.user.keyUser342$2a$10$.zslfggeUqvq.m/5LNSolOsession_id0db80c26bc36a4c1c74c223655dcb092
<% if user_signed_in? %>
**is false**
编辑
<%= session %>
no value
<% if user_signed_in? %>
**is false**
后:
我的routes.rb文件
Cybercellar3::Application.routes.draw do
devise_for :users
get "home/index"
<% if signed_in? %>
**is still false**
EDIT2:
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
我想我找到了我的问题,我的控制器之一
application_controller.rb
#facebook stuff
def current_user
@current_user ||= User.find_by_id(session[:user_id])
end
def signed_in?
!!current_user
end
helper_method :current_user, :signed_in?
def current_user=(user)
@current_user = user
session[:user_id] = user.id
end
#facebook stuff
之后我删除该块它似乎很好地工作:)
我总是用'if current_user' :) – 2012-02-15 08:16:17
和kishie一样。我也总是最终检查current_user。这可用吗? – zsquare 2012-02-15 14:11:56
非常感谢!你结束了我的挫败感。 – Brett 2012-05-06 02:08:38