# Trying not to duplicate actions for ajax

**URL:** <https://www.ruby-forum.com/t/trying-not-to-duplicate-actions-for-ajax/150711>\
**Category:** Rails\
**Created:** [October 11, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/trying-not-to-duplicate-actions-for-ajax/150711 "2008-10-11T21:25:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [October 11, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/trying-not-to-duplicate-actions-for-ajax/150711/1 "2008-10-11T21:25:11Z")

</div>

I’ve got a controller which displays a list of documents in the index  
action. There are action links for each document, ‘view’ and ‘edit’ are  
normal links that go to the pages, but ‘delete’ and ‘publish’ are ajax  
links that replace content in the actions div.

This works perfectly, however I am now trying to implement the ‘view’  
page, and I’m having trouble re-using those ajax actions.

Above the document details in the ‘view’ page there should be a menu  
with ‘edit’, ‘delete’ and ‘publish’. The problem is that the update divs  
are not the same for the index and view pages so the ajax actions don’t  
update anything visible on the ‘view’ page.

i’m not sure if i have explained this very well, so please ask for more  
information if necessary.

Grateful someone has some ideas about re-using the ajax actions in a  
different view with different elements.

Thanks

Matt

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [October 11, 2008, 9:34pm UTC](https://www.ruby-forum.com/t/trying-not-to-duplicate-actions-for-ajax/150711/2 "2008-10-11T21:34:33Z")

</div>

Let me try and clarify a little bit.

the index action loads a partial called ‘actions’ which has the two  
normal and two ajax links. On completion of processing the ajax links,  
the delete link removes the

 for that document and the publish  
re-renders the ‘actions’ partial.

the view action should render a different partial (ie ‘view\_actions’)  
with different update params to the ajax links.

The problem is that when run from the view action, I want the delete  
action to print a message rather than remove the row, and I want the  
publish action to render the view\_actions rather than actions.

I can see a way round this by duplicating the delete and publish actions  
in the controller and modify them slightly but that isn’t DRY and  
doesn’t feel like the right way to do it.

Any tips most welcome 🙂

Thanks

Matt
