2012-07-08 69 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