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

Bill Atkins
Thu, 27 Jan 2005 04:18:35 -0000

Sounds good to me.  Thanks.

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
>
>
>
>


--
$stdout.sync = true
"Just another Ruby hacker.".each_byte do |b|
  (''a''..''z'').step do|c|print
c+"\b";sleep 0.007 end;print b.chr
end; print "\n"