Hopefully this is a softball question.  Say
I have a table "meals" which has "entree_id" and
"dessert_id".

I have parent tables "entrees" and "desserts".

In my data entry controller, I have a new_meal()
action and a create_meal() action.

new_meal loads @entrees and @desserts, and new_meal.rhtml
uses them in a couple of form.collection_select() calls
so I can generate select boxes.

The common paradigm seems to be:

def new_meal
  <create new meal object, fill any appropriate fields>
  <set up other vars needed for view, as noted above>
end

def create_meal
  @meal = Meal.new(params[:meal])
  if @meal.save
    flash[:notice] = "yay"
    redirect_to :action => index
  else
    render :action => 'new_meal'
  end
end

My problem is that if I do the above and incorrectly fill out
the form, then the "render" line is called and fails because
"new_mail.rhtml" now has nil values for the vars that were
supposed to be set up in the new_meal action.

If I instead change "render" to "redirect_to", then the form
generates fine, but apparently error_messages_for() no longer
has anything to report, so I can't tell users what they did wrong.

What am I missing?  This task has got to be about as
common as dirt...

                -glenn
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to