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!

On Dec 12, 1:05 pm, SousChef <sgalva...@gmail.com> wrote:
> 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
>
> On Dec 11, 1:26 am, Andrei Erdoss <erd...@gmail.com> wrote:
>
> > From a quick glance at your code, I see that you use prepsteps in your
> > controller and pre_steps in yourmodels.
>
> > On Fri, Dec 11, 2009 at 5:28 AM, SousChef <sgalva...@gmail.com> wrote:
> > > So I'm a newbie to Rails and attempting to addmultiplemodelsto a
> > > form.
>
> > > I found the Railscast for "Complex Forms, Part 1" at
> > >http://railscasts.com/episodes/73-complex-forms-part-1whichis 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/Taskmodels, but am building a Recipe/Preparation Stepsmodels
> > > to learn Rails. Not sure what's up except my controller needs a method
> > > somewhere.  I'm using Rails 2.3.4.  Any sugggestions?
>
> > > Thanks in advance!!
> > > --------------------------------------
>
> > > Error message:
> > > NoMethodError in RecipesController#new
>
> > > undefined method `prepsteps'
>
> > > Following is my code:
> > > recipes_controller.rb
> > >  def new
> > >   �...@recipe = Recipe.new
> > >    3.times { @recipe.prepsteps.build }
>
> > >    respond_to do |format|
> > >      format.html # new.html.erb
> > >      format.xml  { render :xml => @recipe }
> > >    end
> > >  end
>
> > > recipes\new.html.erb
> > >    <% for prepstep in @recipe.prepsteps %>
> > >        <% fields_for "recipe[prepstep_attributes][]", prepstep do |
> > > prepstep_form| %>
> > >          <p>
> > >            <%= prepstep_form.text_field :step_number %>
> > >            <%= prepstep_form.text_field :step %>
> > >          </p>
> > >        <% end %>
> > >    <% end %>
>
> > > recipe.rb
> > > class Recipe < ActiveRecord::Base
> > >  validates_presence_of :name
>
> > >  has_many :prep_steps, :dependent => :destroy
>
> > >  accepts_nested_attributes_for :prep_steps
> > > end
>
> > > prep_steps.rb
> > > class PrepSteps < ActiveRecord::Base
> > >  has_one :recipe, :dependent => :destroy
>
> > >  validates_presence_of :recipe
> > > 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-t...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > Andrei Erdoss
>
>

--

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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to