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
<center>
<%= current_user.username %> select your next play:<br>
<form action="/games/asses" method="post"
name="playform">
<select id="play" name="play"
onchange="document.playform.submit
();document.playform.reset()">
<option value=""></option>
<option value="1">Rock</option>
<option value="2">Paper</option>
<option value="3">Scissors</option>
</select>
</form>
<div id="outcome">
<%= @whowon || '' '' %>
</div>
</center>
<script type="text/javascript">
Effect.Fade("outcome", { duration: 5.0 })
</script>
===== views/games/play.html.erb
<% if current_user == nil %>
<% redirect_to root_url %>
<% end %>
<div id="top">
<%= render :partial => ''hand'' %>
</div>
<div id="bot">
</div>
<script type="text/javascript">
startClock("../json.dat" );
Effect.Fade("outcome", { duration: 5.0 })
</script>
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.