On 18 Dec 2007, at 19:39, spokra wrote:
>
> what am i missing here . the line a.each { |B| fails with the error
>
> NoMethodError: 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.+
> from (irb):4:in `create_menu''
> from (irb):17
>
a may be, but ret isn''t set to anything, and a quirk of ruby means
that it will be nil.
In addition, using find like that leaves you open to sql injection
problems and your if condition is bogus. Unlike some languages 0 is
not synonymous with false
Fred> but a is an array of menu objects.. HELP!!!
>
>
> def create_menu(menu)
> a = Menu.find(:all, :conditions => "menu = ''" + menu
+ "''", :order
> => "''order''" )
> if a.size then
> ret += "<ul>\n"
> a.each { |b|
> ret += "<li>\n"
> ret += link_to h(b.name), :action => b.controller
> +"/"+b.action, :id => b.name
> ret += "\n"
> ret += create_menu(b.submenu)
> ret += "</li>\n"
> }
> ret += "</ul>\n"
> end
> end
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---