# RESTful action for 'save as'?

**URL:** <https://www.ruby-forum.com/t/restful-action-for-save-as/144597>\
**Category:** Rails\
**Created:** [July 31, 2008, 10:07am UTC](https://www.ruby-forum.com/t/restful-action-for-save-as/144597 "2008-07-31T10:07:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amolk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@amolk](https://www.ruby-forum.com/u/amolk)\
**Post date:** [July 31, 2008, 10:07am UTC](https://www.ruby-forum.com/t/restful-action-for-save-as/144597/1 "2008-07-31T10:07:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amolk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@amolk](https://www.ruby-forum.com/u/amolk)\
**Post date:** [July 31, 2008, 2:39pm UTC](https://www.ruby-forum.com/t/restful-action-for-save-as/144597/2 "2008-07-31T14:39:30Z")

</div>

I should have been more clear on the 2nd paragraph - if I were using  
your  
RESTful api, I’d do a show for the record, get the xml, and then send  
that  
xml to the create action. Your API doesn’t need to provide me with a  
‘copy’  
or ‘save as’ option, as I can just do it myself. You just need a way to  
facilitate it for web users.

---

<div class="post-metadata">

**Author:** ![amolk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@amolk](https://www.ruby-forum.com/u/amolk)\
**Post date:** [July 31, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/restful-action-for-save-as/144597/3 "2008-07-31T14:37:10Z")

</div>

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.
