使用resource.active_for_authentication设计覆盖RegistrationController问题?

时间:2013-06-06 23:25:11

标签: ruby devise ruby-on-rails-3.2

我想覆盖这个控制器,在这一刻创建方法,我已经对它做了一点改动

class RegistrationsController < Devise::RegistrationsController
    def create
      unless session[:invitation_token].blank?
        super
      else
        redirect_to new_user_session_path and return
      end
    end

end

遵循注册流程后,资源在数据库中创建,就像超类定义它一样

  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

但在某种程度上,方法active_for_authetication存在问题?

投掷错误,我无法弄清楚为什么我检查了所有的宝石,它说该方法被其他模块覆盖,正常的定义是

def active_for_authentication?
  true
end

但我没有使用任何覆盖它的模块,所以出于某种原因,它似乎设法无法成功验证,但用户存储在数据库中,我在注册后登录。 / p>

这是我注册用户的配置。

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :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, :username
end

这是我的设计初始化器

Devise.setup do |config|

  config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"

  require 'devise/orm/active_record'
  config.case_insensitive_keys = [ :email ]
  config.strip_whitespace_keys = [ :email ]
  config.skip_session_storage = [:http_auth]
  config.stretches = Rails.env.test? ? 1 : 10
  config.password_length = 6..15
  config.reset_password_within = 6.hours
  config.sign_out_via = :delete


end

0 个答案:

没有答案