a nil object when you didn't expect it!

I'm a new ruby, now i have a newbie problem

I have three model 1. [code] class SfProduct < ActiveRecord::Base   has_many :sf_actions_maps     def sf_add_user_to_action_map()     sf_actions_maps << SfProductMap.new()   end end [/code] 2. [code] class SfProductMap < ActiveRecord::Base   belongs_to :sf_product   belongs_to :sf_user [/code] 3. [code] class SfUser < ActiveRecord::Base   has_many :sf_products_maps [/code]

product controller create code : def create     @sf_product = SfProduct.new()     @sf_product.sf_add_user_to_action_map(@sf_user)     respond_to do |format|       if @sf_activity.save

      else

      end     end

afert user the create actions, the error will be show:

You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.delete

please help me!

The error message should tell you which line of your code is failing. On that line you have probably used a variable that is nil. Possibly you have done a find and it has not found any records.

If you can't see it post the whole error message and stack trace and the bit of code around the error.

Colin