Forum: Ruby on Rails trying not to duplicate actions for ajax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8fa0f5c2bf8ad238baa4e20cb0360ebd?d=identicon&s=25 Matt Harrison (iwasinnamuknow)
on 2008-10-11 21:25
(Received via mailing list)
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
8fa0f5c2bf8ad238baa4e20cb0360ebd?d=identicon&s=25 Matt Harrison (iwasinnamuknow)
on 2008-10-11 21:34
(Received via mailing list)
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 :)

Thanks

Matt
This topic is locked and can not be replied to.