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

Sarah Wedde
Thu, 27 Jan 2005 19:30:41 -0000

This is what I''ve been doing--I think it came from the original
tutorial on
the wiki.

def new
        @category = Category.new
        @target = "create"
        render_action "edit"
end

def edit
        @category = Category.find(@params["id"])
        @target = "update"
end

and then in the edit form

<%= form_tag({:action => @target}) %>

Sarah



On 28/1/05 5:49 AM, "Brian L."
<zorander-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> 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