So I'm a newbie to Rails and attempting to add multiple models to a
form.
I found the Railscast for "Complex Forms, Part 1" at
#73 Complex Forms Part 1 - RailsCasts which is from
2007 and at the point where the moderator, Ryan, says "Let's take a
look at our code..." and refreshes the UI and in the Railscast we see
3 Tasks below the Project. However, when I refresh my project screen,
my code shows a "NoMethodError" in the Controller with an undefined
method for the prepsteps that were added. I'm not following the
Project/Task models, but am building a Recipe/Preparation Steps models
to learn Rails. Not sure what's up except my controller needs a method
somewhere. I'm using Rails 2.3.4. Any sugggestions?
Hi Andrei,
Thanks for the quick feedback. I changed all prepsteps to prep_steps,
but now I'm getting an uninitialized constant error in my Recipe
controller for the following line:
3.times { @recipe.prep_steps.build }
BROWSER DISPLAY:
NameError in RecipesController#new
uninitialized constant Recipe::PrepStep
ERROR FROM THE CONSOLE:
NameError (uninitialized constant Recipe::PrepStep):
app/controllers/recipes_controller.rb:28:in `new'
app/controllers/recipes_controller.rb:28:in `times'
app/controllers/recipes_controller.rb:28:in `new'
-e:1:in `load'
-e:1
I took out the 3.times & curly braces & tried just the
"@recipe.prep_steps.build" and I got the same error. I changed the
prep_steps to a number of variations (prepsteps, PrepSteps, PrepStep)
and got other various errors. Any thoughts? Is the underscore the
issue?
Thanks in advance!
Seth
Or as a more general question, I reviewed the Railscast mentioned
above & Ryan Bates says that the Railscast shows a way to do multiple
models in one form by keeping the code tucked in the models and not
the controllers. Since the Railscast was done in 2007, has a
preferred method of doing multiple models in one form emerged? Is it
preferable to put code in the models keeping the controllers light or
is it preferred to put the code in the controllers and keep the models
light? Or is this still a design preference for the developer to
choose?
Thanks in advance for enlightment!