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
===== views/games/play.html.erb
<% if current_user == nil %>
<% redirect_to root_url %>
<% end %>
–
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.