On 15 April 2011 11:08, seth shao
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> 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
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
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.