Hi all, Merry X''mas first :-) I have "Product","Category","Subcategory" 3 Model, and when new "Product", I want to use "Dynamic Select Menus" just like Ryan mentioned in http://railscasts.com/episodes/88-dynamic-select-menus I have everything down. But when I visit the js file, I got following error Showing app/views/javascripts/dymanic_categories.js.erb where line #3 raised: 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.each Extracted source (around line #3): 1: // javascripts/dynamic_categories.js.erb 2: var subcategories = new Array(); 3: <% for subcategory in @subcategories -%> 4: categories.push(new Array(<%= category.id %>, ''<%=h subcategory.subcategory_name %>'', <%= subcategory.id %>)); 5: <% end -%> Anyone got an idea, how does it happen? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What does the controller set @subcategories to before rendering the javascript? --wpd --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Partrick, Before the controller rendering the Javascript, @subcategories = Subcategory.find(:all) On Dec 26, 3:05 am, "Patrick Doyle" <wpds...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What does the controller set @subcategories to before rendering the > javascript? > > --wpd--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Showing app/views/javascripts/dymanic_categories.js.erb where line #3 > raised:"dymanic"? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, Eric Thank you very much for help. I checked my codes again, yes I made a typo here, it should be "dynamic_categories" here And now when I visit app/views/javascripts/dynamic_categories.js.erb I can get the array But, question comes again :-( I can get category and subcategory list in my item/new view But, when I change the value of category the value of subcategory doesn''t change! I checked with web inspector, I got this error message"TypeError: Value undefined (result of expression document.observe) is not object." It seems my result of document.observe is not correct? How can I fix it? On Dec 26, 8:01 pm, Eric <ericgh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Showing app/views/javascripts/dymanic_categories.js.erb where line #3 > > raised: > > "dymanic"?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
OK, guys Finally I figured it out. I missed the <%= javascript_include_tag :defaults %> in my layout. Now everything goes fine. Thank you very much for your help. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---