Forum: Ruby on Rails One question about Dynamic Select Menus

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3949b43a989430f9959e816e105cbbcc?d=identicon&s=25 Jette Chan (jette)
on 2008-12-25 06:20
(Received via mailing list)
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?
Ed437e52d8d6720308720e7e678f3e6d?d=identicon&s=25 Patrick Doyle (Guest)
on 2008-12-25 20:05
(Received via mailing list)
What does the controller set @subcategories to before rendering the
javascript?

--wpd
3949b43a989430f9959e816e105cbbcc?d=identicon&s=25 Jette Chan (jette)
on 2008-12-26 09:00
(Received via mailing list)
Hi Partrick,
Before the controller rendering the Javascript,
@subcategories = Subcategory.find(:all)
D93ae163042e0a937941e0ba4d8ed5d7?d=identicon&s=25 Eric (Guest)
on 2008-12-26 13:02
(Received via mailing list)
> Showing app/views/javascripts/dymanic_categories.js.erb where line #3
> raised:

"dymanic"?
3949b43a989430f9959e816e105cbbcc?d=identicon&s=25 Jette Chan (jette)
on 2008-12-28 11:17
(Received via mailing list)
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?
3949b43a989430f9959e816e105cbbcc?d=identicon&s=25 Jette Chan (jette)
on 2008-12-28 17:52
(Received via mailing list)
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.
This topic is locked and can not be replied to.