You'll get invited to our Meetups as soon as they're scheduled!
The East Bay Ruby Meetup Group Message Board › Extending Parent to multiple Children in extended "Rails 2.3: Associate
| Seth Galvarro | |
|
|
Rookie question (literally - been learning rails for about a month):
So I attended the "New in Rails 2.3: Associated models accepts_nested_attributes_for" meeting and am now trying to get multiple children onto a form to be associated to the parent that is also on the form. I found an example from Rails Forum to do this at http://railsforum.com... At the step in the example: # in projects_controller.rb def new @project = Project.new 5.times { @project.tasks.build } end I've added the 5.times statement in my controller, but now I toggle back and forth between 2 errors. I either get a "NameError ProjectsController, uninitialized constant Project::task" or a "No Method Error in Controller... undefined method 'child'" I've been going between using plural (i.e. with 's' at the end) for the child's name & singular for the child's name. What am I missing? What information do I need to post to make this clear? Any help will be helpful. |
| Wolfram Arnold | |
|
|
Seth,
I can't tell what the problem is from that slim piece of code; the first error would seem to indicate your model is missing the has_many :tasks declaration, the second is less clear because you're not showing the view code. I personally found the Rails's own test suite most helpful in understanding this feature. One thing you can always be sure of when documentation is failing you is to look at the tests that actually exercise the code. The Active Records tests are pretty well structured. The examples I used in my presentation borrow from them... Find your Active Record gem install directory and browse to the test folder and look inside "cases". To find the install directory, you can use this: gem list -d activerecord Best, Wolf |