Ruby on rails 3 仅在Safari中出现Rails 3错误-ActiveRecord::RecordNotFound(找不到具有auth#u令牌=)的用户:

Ruby on rails 3 仅在Safari中出现Rails 3错误-ActiveRecord::RecordNotFound(找不到具有auth#u令牌=)的用户:,ruby-on-rails-3,Ruby On Rails 3,在我的Rails3应用程序中,我遵循Railscast#274以获得重置密码,我在Safari中遇到了一个奇怪的问题。如果我在Heroku中运行我的应用程序,当我转到根目录时会出现以下错误: ActiveRecord::RecordNotFound (Couldn't find User with auth_token = ): app/controllers/application_controller.rb:39:in `lookup_user' app/controllers/applic

在我的Rails3应用程序中,我遵循Railscast#274以获得重置密码,我在Safari中遇到了一个奇怪的问题。如果我在Heroku中运行我的应用程序,当我转到根目录时会出现以下错误:

ActiveRecord::RecordNotFound (Couldn't find User with auth_token = ):
app/controllers/application_controller.rb:39:in `lookup_user'
app/controllers/application_controller.rb:32:in `current_user'
app/controllers/application_controller.rb:54:in `logged_in?'
app/controllers/users_controller.rb:8:in `new'
如果使用Firefox和Chrome(在匿名模式下),它可以工作。在Safari中,我发现如果我得到错误,我可以导航到
/logout
,使其消失。然后页面呈现得非常完美

这是我的
/logout
root
路径:

match "/logout" => "sessions#destroy", :as => "logout"
root :to => "users#new"
这是我在
sessions\u controller
中的
destroy
操作:

def destroy
  reset_session
  cookies.delete(:auth_token)
  redirect_to root_path, :notice => "You successfully logged out"
end
protected

  def current_user
    @current_user ||= lookup_user
  end

  def lookup_user
    if session[:user_id]
      User.find_by_id(session[:user_id])
    elsif cookies[:auth_token]
      User.find_by_auth_token!(cookies[:auth_token])
    end
  end
我的
应用程序\u控制器

def destroy
  reset_session
  cookies.delete(:auth_token)
  redirect_to root_path, :notice => "You successfully logged out"
end
protected

  def current_user
    @current_user ||= lookup_user
  end

  def lookup_user
    if session[:user_id]
      User.find_by_id(session[:user_id])
    elsif cookies[:auth_token]
      User.find_by_auth_token!(cookies[:auth_token])
    end
  end
最后,这里是我在
users\u controller
中的
new
操作:

def destroy
  reset_session
  cookies.delete(:auth_token)
  redirect_to root_path, :notice => "You successfully logged out"
end
protected

  def current_user
    @current_user ||= lookup_user
  end

  def lookup_user
    if session[:user_id]
      User.find_by_id(session[:user_id])
    elsif cookies[:auth_token]
      User.find_by_auth_token!(cookies[:auth_token])
    end
  end
def新 @user=user.new @user.profile=profile.new 如果你登录了? 重定向到配置文件路径(当前用户) 结束 结束

我所尝试的:

要更改
new
操作以删除Cookie,请执行以下操作:

如下所示的rake任务:

两者似乎都不起作用。有人能帮我弄清楚吗

每当您重新生成user:auth_代码时,您都需要删除该域的cookie。在生产环境中,您不应该重新生成:auth_代码,除非用户编辑他们的cookie,否则您永远不会出现此问题

此外,我已经在railscast.com认证(修订版)解决方案上发布了回复,以便Ryan可以查看


祝你好运

谢谢你的回复。我将你的代码添加到我的
查找
方法中,它似乎使我的应用程序崩溃。我尝试使用/不使用
return nil
,并删除了除
cookies.delete(:auth_token)
之外的所有内容,但这与我在上面遇到的错误相同。