Hi:
I''m trying to manually append objects to an instance variable that is
just an array of objects. Here''s my controller code:
@tasks = Task.find(:all, :conditions => "entity_id
#{session[:user].id}")
for t in @tasks
if Subtasks.find(:first, :conditions => "child_id = #{t.id}") !=
nil
@mtasks << t
end
end
However, when I execute, I get an error:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
Am i incorrectly referencing the object "t"? I haven''t
previously
declared or used "mtasks".
Any help you could provide would be greatly appreciated.
Thanks!
Mike
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 2/12/07, Mike Dershowitz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi: > > I''m trying to manually append objects to an instance variable that is > just an array of objects. Here''s my controller code: > > @tasks = Task.find(:all, :conditions => "entity_id > #{session[:user].id}") > for t in @tasks > if Subtasks.find(:first, :conditions => "child_id = #{t.id}") != nil > @mtasks << t > end > end > > However, when I execute, I get an error: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.<< > > Am i incorrectly referencing the object "t"? I haven''t previously > declared or used "mtasks". > >Looks like a typo: "@tasks" vs. "@mtasks". Chad --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You didn''t initialize the @mtasks as an array. Try this:
@tasks = Task.find(:all, :conditions => "entity_id
#{session[:user].id}")
@mtasks = Array.new()
for t in @tasks
if Subtasks.find(:first, :conditions => "child_id = #{t.id}")
!nil
@mtasks << t
end
end
On 12 Feb., 15:28, Mike Dershowitz
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi:
>
> I''m trying to manually append objects to an instance variable that
is
> just an array of objects. Here''s my controller code:
>
> @tasks = Task.find(:all, :conditions => "entity_id >
#{session[:user].id}")
> for t in @tasks
> if Subtasks.find(:first, :conditions => "child_id =
#{t.id}") != nil
> @mtasks << t
> end
> end
>
> However, when I execute, I get an error:
>
> You have a nil object when you didn''t expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.<<
>
> Am i incorrectly referencing the object "t"? I haven''t
previously
> declared or used "mtasks".
>
> Any help you could provide would be greatly appreciated.
>
> Thanks!
>
> Mike
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---