2012-11-16 23 views
0

我的設計設置中發生了一些非常奇怪的事情。設計中的空指針錯誤

我有一個自定義的ConfirmationsController,用於設計自定義行爲。

我的客戶模型:

class Customer 
include Mongoid::Document 

after_create  :prepare_demo_app 

devise :validatable, 
     :registerable, 
     :database_authenticatable, 
     :confirmable, 
     :trackable, 
     :rememberable, 
     :recoverable, 
     :mailchimp 

## Confirmable 
field :confirmation_token, :type => String 
field :confirmed_at,   :type => Time 
field :confirmation_sent_at, :type => Time 

我定製的控制器

class ConfirmationsController < Devise::ConfirmationsController 
    def create 
     puts "resource #{resource}" 
     puts "resource name #{resource_name}" 
     super 
    end 
enter code here 

我的routes.rb

devise_for :customers, 
       :controllers => {:confirmations => "confirmations" }, 
       :skip => [:sessions, :passwords], :format => false do 
       #... other gets and posts but nothing to do with confirmations 
       #... 
    end 

當我打這個控制器按我的路線文件I輸入電子郵件。點擊提交併獲取資源的空指針。但不是資源名稱。有沒有人有任何想法,我可能會錯過或爲什麼客戶將通過爲空?

回答

0

resource沒有被設置在任何地方。在default ConfirmationsController,設計初始化resource像這樣(取決於你正在運行的版本):

self.resource = resource_class.send_confirmation_instructions(resource_params) 

如果你把super之前你puts陳述,resource應設置。

+0

恐怕那是不可能的。一旦調用super,就會調用一個空指針異常。即使只使用超級創建方法,也會發生這種情況。值得注意的是,resource_params也是零。 – OVERTONE