RESTful action for 'save as'?

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.

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.

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.