多步向导中的验证

时间:2012-07-08 02:38:43

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

我试图在多步骤向导上设置验证(使用邪恶的宝石和此GUIDE)。我输入一些用户信息的第一步(使用Devise + Registrations)但是当我提交时我收到以下错误:

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

1 个答案:

答案 0 :(得分:1)

您需要将“状态”添加到用户模型,然后从向导控制器将其设置为步骤值。

指南指示您在“解决方案”部分的开头执行迁移:

class ProductStatus < ActiveRecord::Migration

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

  def down
    remove_column :product, :status
  end

end