trying not to duplicate actions for ajax

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.



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 <tr> 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 :slight_smile: