I know this question has been asked several times but I am having following the trouble.
I am creating a simple hangman game, and I have created a keyboard, so there are 26 forms that look like this:
<%= form_for @puzzle, :remote => true, :html => {:class => 'keyq'} do |f|%>
<%= f.hidden_field :letters_guessed, value: "Q" %>
<% end %>
I store the letters in an array type db field :letters_guessed
which I then use to loop to see if the user has guessed the letter.
<div class="mystery">
<% @puzzle.word.length.times do |digit| %>
<% letter = @puzzle.word[digit] %>
<% if @puzzle.word[digit] == " " %>
<br>
<% elsif @puzzle.letters_guessed.include?(letter.upcase)%>
<%= letter %>
<% else %>
<%= "_" %>
<% end %>
<% end %>
</div>
So essentially, I need to update the mystery div with the new array. As of now, when I submit the form, nothing happens (to be expected I suppose).
Here is my controller action
def update
@puzzle.letters_guessed = @puzzle.letters_guessed + [params[:puzzle][:letters_guessed]]
@puzzle.save
respond_to do |format|
format.html
format.js
end
The idea here is that I create a new array, and save it. Now comes the part I'm not sure what to do with the renders.
I've created a _puzzle.js file in the same directory as the other views... How do I get the new array back to my view without actually refreshing the page?