<div id="captcha_widget">
  <p>Please type in the letters and numbers you see in the picture below.</p>

  <% random_string = ActiveSupport::SecureRandom.hex(10) %>

  <%= captcha_image random_string %>
  <br />
  <%= captcha_audio random_string %>
  <br />
  <%= link_to 'Refresh challenge', '#', :class => 'refresh_link', :id => 'captcha_refresh' %>

  <input type="text" id="captcha_response_field" name="captcha_response_field" />
  <input type="hidden" id="captcha_string" name="captcha_string" value="<%= random_string %>" />
  <%= error_messages_for_field signature, :humanity, :server_only_validation => true %>
</div>

<% content_for :js do %>
  <script type="text/javascript">
  //<![CDATA[
    $().ready(function() {
      $('#captcha_refresh').click(function(){
        var randomString = Math.random().toString(36).substring(2);
        var newImageSrc = $('#captcha_image').attr('src').replace(/random\=(\w+)&/, ('random='+randomString+'&') );
        var newAudioSrc = $('#captcha_audio').attr('href').replace(/random\=(\w+)&/, ('random='+randomString+'&') );

        $('#captcha_image').attr('src', newImageSrc);
        $('#captcha_audio').attr('href', newAudioSrc);
        $('#captcha_string').val(randomString);

        return false;
      });
    });
  //]]>
  </script>
<% end %>

<div id="captcha_widget">
  <p>Please type in the letters and numbers you see in the picture below.</p>

  <% random_string = SecureRandom.hex(10) %>

  <%= captcha_image random_string %>
  <br />
  <%= captcha_audio random_string %>
  <br />
  <%= link_to 'Refresh challenge', '#', :class => 'refresh_link', :id => 'captcha_refresh' %>

  <input type="text" id="captcha_response_field" name="captcha_response_field" />
  <input type="hidden" id="captcha_string" name="captcha_string" value="<%= random_string %>" />
  <%= error_messages_for_field signature, :humanity, :server_only_validation => true %>
</div>

<% content_for :js do %>
  <script type="text/javascript">
  //<![CDATA[
    $().ready(function() {
      $('#captcha_refresh').click(function(){
        var randomString = Math.random().toString(36).substring(2);
        var newImageSrc = $('#captcha_image').attr('src').replace(/random\=(\w+)&/, ('random='+randomString+'&') );
        var newAudioSrc = $('#captcha_audio').attr('href').replace(/random\=(\w+)&/, ('random='+randomString+'&') );

        $('#captcha_image').attr('src', newImageSrc);
        $('#captcha_audio').attr('href', newAudioSrc);
        $('#captcha_string').val(randomString);

        return false;
      });
    });
  //]]>
  </script>
<% end %>

Use SecureRandom instead of ActiveSupport::SecureRandom
Use SecureRandom instead of ActiveSupport::SecureRandom

ActiveSupport::SecureRandom was added to maintain compatibility between
Ruby 1.8.7 and later version that had SecureRandom built-in. Since the
minimum version for Rails 4.0 and above is Ruby 1.9.3 then we can just
use the built-in library.
