I am trying to follow the guide for partial validation on object using the wizard gem, but I keep getting the error undefined method `include?' for nil:NilClass, cant understand what is wrong, have tried to follow the step by step instructions.
The error in the log shows.
NoMethodError - undefined method `include?' for nil:NilClass:
app/models/property.rb:22:in `active_or_tenants?'
Here is my steps controller.
class Properties::BuildController < ApplicationController
include Wicked::Wizard
steps :tenant, :confirmed
def show
@property = Property.find(params[:property_id])
@tenants = @property.tenants.new(params[:tenant_id])
render_wizard
end
def update
@property = Property.find(params[:property_id])
params[:property][:status] = step.to_s
params[:property][:status] = 'active' if step == steps.last
@property.update_attributes(params[:property])
render_wizard @property
end
def create
@property = current_user.properties.build(params[:property])
logger.info @property.attributes
if @property.save
flash[:success] = "Tenant Added"
redirect_to wizard_path(steps.second, :property_id => @property.id)
else
render 'edit'
end
end
end
Property.rb
class Property < ActiveRecord::Base
attr_accessible :name, :address_attributes, :tenants_attributes, :property_id, :status
belongs_to :user
has_one :address, :as => :addressable
accepts_nested_attributes_for :address, :allow_destroy => true
has_many :tenants
accepts_nested_attributes_for :tenants, :allow_destroy => true
validates :name, :presence => true
validates :address, :presence => true
validates :tenants, :presence => true, :if => :active_or_tenants?
def active?
status == 'active'
end
def active_or_tenants?
status.include?('tenants') || active?
end
end
Let me know if you need any other parts added to the question. Thanks in advance.
include?' for nil:NilClass: app/models/property.rb:22:in
active_or_tenants?' – Hamelstatus.include?('tenants') || active?
with(status || '').include?('tenants') || active?
– Gaitskell