I have two actions, create and index. The index view has a list of find(:all) objects and also a form for creating new objects. If the form is valid upon creation, everything works (it is redirected to the index page with the new object listed). If validation fails, I get the error. My questions is, is it possible to do something like this?
on 2007-03-20 20:29
on 2007-03-21 04:43
Sometimes this happens when you have code like this: def create @foo = Foo.new(params[:foo]) if @foo.valid? flash[:success] = 'Foo created.' redirect_to :action => 'show', :id => @foo else render :action => 'new' end end If it works on a successful create but not on a render to 'new' then you are likely loading objects in the 'new' action that is not loaded in 'create'. Example: def new @foo = Foo.new @bars = Bar.find(:all) end When you render the 'new' template from the create action you may need to reload the @bars (in this example). Hope this helps. -- Zack Chandler http://depixelate.com
on 2007-03-21 05:47
That didn't even cross my mind! Makes perfect sense. Thanks!