Re: Re: Sharing code between the edit and create actions

Brian L.
Thu, 27 Jan 2005 16:49:56 -0000

Shouldn''t the edit form target the ''update'' action
and the new form
target ''create''? Unless you''re doing something
creative like a unified
action that checks for object id to be non-null and then
creates/updates OR saving @rec first, I can''t see how this would work.

Also, the edit form probably needs a hidden field for ID and the
create form does not.

I usually use a _form.rhtml partial but only include the body of the
form, that way I can have different form targets in edit and new and
add the hidden id field to edit.

Brian



On Wed, 26 Jan 2005 20:23:40 -0500, Eric Anderson
<eric-ANzg6odk14w@public.gmane.org> wrote:
> Bill Atkins wrote:
> > Is there an easy way to reuse the code used to generate an edit form
> > to generate the form for the create action?  In the ONLamp tutorial, a
> > custom edit page is written, but the changes have no effect on
> > creating a recipe.
>
> Why not just render the edit template in the create action. I
haven''t
> read the article so I don''t know the exact models but something
like
> this works great for me in my projects.
>
> RecipeController < ActionController::Base
>
> def new
>         @rec = Recipe.new
>         render_action ''edit''
> end
>
> def edit
>         @rec = Recipe.find @params[''id'']
> end
>
> end
>
> Then your edit.rhtml file will simply read from the @rec object. It will
> be either blank or filled in with all the details of an existing object.
>
> Eric
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>


--
The years ahead pick up their dark bags.
They move closer. There''s a slight rise in the silence

then nothing.
--
(If you''re receiving this in response to mail sent to
bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned
This is my new address,
but mail will be forwarded here indefinitely)