0

我正在将 Rails 2 应用程序迁移到 Rails 3 并且必须使用新的身份验证解决方案,因为不再支持 restful_authentication。我正在尝试设计,但遇到了问题。

我有一个登录页面,然后将您定向到该应用程序。您也可以在不登录的情况下使用该应用程序,但某些选项在您登录之前不可用。

登录后,Devise 说我已通过一条消息登录,但 anycurrent_user将评估为nilcurrent_user.blank?评估为true并且 anyuser_signed_in?将评估为false。奇怪signed_in?地评估为true。检查我的会话数据显示warden.user.user.id包含正确的用户 ID 并且存在 csrf 令牌。在视图和控制器中都是如此。

这是routes.rb

MyApp::Application.routes.draw do

  devise_for :users

  match "/:controller(/:action(/:id))"  
  match "/:controller(/:action(/:id))(.:format)"
  match "/:controller(/:action(.:format))"

devise_scope :user do
 get 'signup', :to => 'devise/registrations#new'
 get 'login', :to => 'devise/sessions#new'
 get 'signout', :to => 'devise/sessions#destroy'
end 
   root :to => 'main#design'

end

用户.rb

require 'digest/sha1'

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :confirmable, :validatable,
         :encryptable, :encryptor => :restful_authentication_sha1

  attr_accessible :email, :password, :password_confirmation, :remember_me, :profile_company, :profile_state, :profile_city, :profile_postcode, :profile_country, :profile_phone, :profile_address

  validates_length_of       :name,     :maximum => 100    
  validates_presence_of     :email
  validates_length_of       :email,    :within => 6..100
  validates_uniqueness_of   :email


  def profile_complete?
    if !(self.profile_address.blank? || self.profile_city.blank? || self.profile_state.blank? || self.profile_phone.blank? || self.name.blank? || self.state != 'active')
      true
    else
      false
    end
  end

end

我在 SO 上看到了很多类似的问题,但似乎没有一个答案适合我的情况。任何帮助将不胜感激,谢谢!

编辑: warden.authenticate(:scope => :user)返回我期望current_user返回的内容。

4

1 回答 1

0

我相信我已经解决了这个问题,restful_authentication 插件添加了一个 UsersHelper 文件,我认为它以某种方式干扰了 Devise 处理 User 类的方式。

于 2013-07-17T18:16:48.897 回答