I’m trying to get two things done after a user clicks on a link:
- Delete a div
- Add another element at the bottom of the page
I played with Rails link_to_remote and what I get with the code below is that the element is added before the div is deleted:
<%= link_to_remote "✓",
:url => {
:controller => :movies,
:action => :mark_as_seen,
:movie => movie,
:render => 'movie' },
:success => "Effect.Fade('movie_#{movie.id}_wrapper', { duration: 0.4 })",
:update => "movies", :position => "bottom",
:failure => "alert('Ooops! An error occurred.')"
%>
I tried to put :update and :position in a :complete callback, but nothing happened. And when I put both of them in the :success callback (after Effect.Fade), all I get is a parsing error.
Any idea?
Thanks,
Kevin
I am not entirely sure if i understand correctly, but i am guessing you want the div to be deleted before the :update action takes place.
As usual this is surprisingly simple 🙂
so just replace the
:successwith:beforewill do that first. Hope this does what you want 🙂The explanation is simple: the
:successaction is executed once the complete action is succesfully ended, so also the update. The:beforeaction is executed before the remote action is executed.For instance i use this all the time to show a spinner during a remote action.