# Div disappearing when enclosed partial re-rendered

**URL:** <https://www.ruby-forum.com/t/div-disappearing-when-enclosed-partial-re-rendered/180753>\
**Category:** Rails\
**Created:** [December 28, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/div-disappearing-when-enclosed-partial-re-rendered/180753 "2009-12-28T15:25:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RVince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@RVince](https://www.ruby-forum.com/u/RVince)\
**Post date:** [December 28, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/div-disappearing-when-enclosed-partial-re-rendered/180753/1 "2009-12-28T15:25:35Z")

</div>

Below is controller code wherein asses gets called, and subsequently  
(re) renders the "hand’ partial (which is enclosed in the view  
“play” (which is what was originally called to invoke this whole  
thing). It contains javascript to invoke the asses() method in the  
controller, below. However, when I invoke asses (from the javascript)  
the bot div disappears – and I need it because I have javascript in  
application.js that is reading the json file created in asses() and  
replacing the innerHTML in the bot div.

Why does my bot div disappear when asses in the controller is invoked?  
Thanks, R.Vince

===== controllers/games\_controller.rb

class GamesController \< ApplicationController  
skip\_before\_filter :verify\_authenticity\_token

def play

end

def asses  
# do some stuff then…  
t = Time.now  
@whowon = t.strftime(“%H:%M:%S”)  
if outcome != 0  
totplays = current\_user.plays + 1  
totwins = current\_user.wins  
if outcome \> 0  
totwins = totwins + 1  
@whowon = @whowon \<\< " – you won!"  
else  
@whowon = @whowon \<\< " – you lost."  
end  
totpercent = totwins.to\_f / totplays.to\_f \* 100  
current\_user.update\_attributes(:plays =\> totplays, :wins =\>  
totwins, :percent =\> totpercent)  
else  
@whowon = @whowon \<\< " – Nobody won - tie!"  
end

```
 x = User.find(:all, :conditions => ["percent is not null"], :limit

```

=\> 10, :order =\> “percent DESC”).collect {|p| [ p.username,  
p.percent]}  
#puts x.to\_json  
File.open(‘public/json.dat’, ‘w’) do |file|  
file.puts x.to\_json  
end

```
 render :partial => 'hand' , :layout => 'application'

```

end  
end

===== views/games/\_hand.html.erb

 \<%= current\_user.username %\> select your next play:  
 Rock Paper Scissors 
 \<%= @whowon || ' ' %\> 

===== views/games/play.html.erb

\<% if current\_user == nil %\>  
\<% redirect\_to root\_url %\>  
\<% end %\>

 \<%= render :partial =\> 'hand' %\>

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
