# Form\_remote\_tag comes back before saving really done?

**URL:** <https://www.ruby-forum.com/t/form-remote-tag-comes-back-before-saving-really-done/160145>\
**Category:** Rails\
**Created:** [February 12, 2009, 8:11am UTC](https://www.ruby-forum.com/t/form-remote-tag-comes-back-before-saving-really-done/160145 "2009-02-12T08:11:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [February 12, 2009, 8:11am UTC](https://www.ruby-forum.com/t/form-remote-tag-comes-back-before-saving-really-done/160145/1 "2009-02-12T08:11:45Z")

</div>

Hi,

I am having troubles with a form\_remote\_tag.  
I have this form:

\<% form\_remote\_tag :url =\> { :action =\> ‘create’, :controller =\>  
‘invitations’ } do %\>  
\<%= hidden\_field\_tag ‘invite’, user.id %\>  
\<%= hidden\_field\_tag ‘command’, ‘invite\_user’ %\>  
\<%= submit\_tag(‘Invite’) %\>  
\<% end %\>

That ends up if the a controllers function (after entering from  
create…):

def invite\_user(friend\_to\_invite)  
invited\_user = User.find(friend\_to\_invite)  
current\_user.request\_friendship\_with(invited\_user)  
invitation = Invitation.new  
invitation.user\_id = current\_user.id  
invitation.status = 0

```
if invitation.save

   @pending_friends_by_me = current_user.pending_friends_by_me
   puts "@pending_friends_by_me"
   puts @pending_friends_by_me
   puts "/@pending_friends_by_me"

   render :update do |page|
   page[:sent_invitations].replace_html :partial =>

```

“sent\_invitations”  
end

```
  return
end

```

end

* * *

\_sent\_invitations is the partial that shows the contents of  
@pending\_friends\_by\_me. So you press the button on the form and this  
partial is updated with the current invitations sent.

THE PROBLEM

Whe the partial is updated from the function above it still doesn’t  
contain the updated @pending\_friends\_by\_me, the last invitation is not  
visible. It returns to the view but the contents are still the same. If  
I just refresh the page then the partial gets all the invitations.

How to solve this?

* * *

I went to the model and used the after\_save callback, when that is  
called inspecting the invitations then all of them are already present.  
But didn’t have access to render functions there, and I don’t think I  
should actually call it from ther anyway.

Any hints?

Thanks.

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [February 12, 2009, 8:46am UTC](https://www.ruby-forum.com/t/form-remote-tag-comes-back-before-saving-really-done/160145/2 "2009-02-12T08:46:56Z")

</div>

try a  
current\_user.reload  
or  
current\_user.pending\_friends\_by\_me.reload  
in your controller after the save.

maybe this helps.

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [February 12, 2009, 8:52am UTC](https://www.ruby-forum.com/t/form-remote-tag-comes-back-before-saving-really-done/160145/3 "2009-02-12T08:52:30Z")

</div>

Ha!

current\_user.pending\_friends\_by\_me.reload  
Yeah that fixed it!

Thanks MaD!
