Conceptually you have to break down what REST is vs what the user sees.
See, at the REST level, it''s still a create, even though it seems like
something else. It''s terribly rare that you need any additional actions
in
the controller. New and Edit are not part of REST; they are there just to
show your users the forms to manipulate data. If you were using XML with
your REST service, you''d simply pass XML directly to the create action
or
update action.
If I went to /items/25/edit, I might see a form with all the fields on it
and a button at the botom which goes to the update action. A
''copy'' button
could also be present. Give each button its own name (the default is
''commit'' if you use submit_tag) and then in the update action,
do a quick
params check. if the name is ''copy'' then do the save-as stuff,
and if the
name is ''commit'' use the normal update stuff.
You could keep it really clean by using a before_filter to intercep the
copy, which would keep the update action nice and clean. (if
params[:copy] Item.create_new_from(params) / redirect_to items_url / end)
So aside from a private method for the before_filter, no new controllerm
methods.
That''s just how I would do it. I am sure there are other ways.
On Wed, Jul 30, 2008 at 1:48 PM, amolk
<Kelkar.Amol-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> Hi all,
>
> I would like to show the user a unified ''overwrite existing or
create
> new item'' page - similar to a ''save as'' dialog.
In that page the user
> would either select from existing items (to overwrite that item) or
> type a unique new title to save as a new item.
>
> I am thinking of getting rid of ''new'' and
''edit'' actions and replacing
> them with a ''save'' action AND getting rid of
''create'' and modifying
> ''update'' action to do both tasks.
>
> Is there a better way to achieve this without breaking the RESTful
> model?
>
> Thanks!
> --- Amol.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---