2012-07-08 61 views
1

我試圖在多步向導(使用邪惡的寶石和這個GUIDE)上設置驗證。第一步我輸入一些用戶信息(使用設計+註冊),但是當我認爲我得到以下錯誤:多步向導中的驗證

NoMethodError in RegistrationsController#create 

undefined method `include?' for nil:NilClass 
Rails.root: /Users/nelsonkeating/Desktop/remindeal1 

Application Trace | Framework Trace | Full Trace 
app/models/user.rb:54:in `active_or_address?' 


Class User 
    validates_presence_of :address, :presence => true, :if => :active_or_address? 

    def active_or_address? 
    status.include?('address') || active? 
    end 

def active? 
    status == 'active' 
end 
+0

哪裏是「狀態」申報?它是零,所以你不能調用它的功能,對吧?或者該變量包含在內? – 2012-11-06 20:48:42

回答

1

你需要「狀態」添加到用戶模型,並從嚮導控制器將其設置爲步驟的值。

該指南指導您在「解決方案」部分的開始執行遷移:

class ProductStatus < ActiveRecord::Migration 

    def up 
    add_column :products, :status, :string 
    end 

    def down 
    remove_column :product, :status 
    end 

end