是否可以在Rails中使用json进行simple_captcha?

时间:2016-07-26 16:44:51

标签: ruby-on-rails json

是否可以在Rails中使用带有json的simple_captcha2? 我需要将图像发送到客户端(angularjs),显示它,读取答案并通过json将其发送到服务器(Rails)以验证它。

我知道什么时候

  

<%= show_simple_captcha%>

在数据库(示例)中:

context.done(error, response)

,图片是:

select * from simple_captcha_data 
id:
key: "94f701cc098d8f70a84e081a03a19994bb3c4b62";
value: "LQQNOK";
created_at: "2016-07-26 16:52:44.389791";
updated_at: "2016-07-26 16:52:44.389791"

键+时间,创建键的时间

例如,如果我用于:通过PasswordsController处理#create as HTML

http://.../simple_captcha?code=94f701cc098d8f70a84e081a03a19994bb3c4b62&time=1469551964

所以我只需要知道如何在simple_captcha_data中创建新记录并知道它的时间?

1 个答案:

答案 0 :(得分:1)

在控制器中包含下一个代码:

include SimpleCaptcha::ViewHelper

def name_of_function(options = {})
    key = simple_captcha_key(options[:object])
      if options[:multiple] === false
        # It's not the first captcha, we only need to return the key
        key
      else
        # It's the first captcha in the page, we generate a new key
        set_simple_captcha_data(key, options)
      end
end

收到密钥 key_captcha 后,您会在应用图片中显示,例如:

<div class='simple_captcha'>
  <div class='simple_captcha_image'>
    <img src="{{protocolo}}://{{serverIp}}/simple_captcha?code={{key_captcha}}" alt="Smiley face" height="50" width="120">
  </div>
  <div class='simple_captcha_field'>
    <input id="captcha_text" type="text" value='' placeholder="Introduzca el texto">
  </div>
</div>

这就是全部,现在你可以发送&#34;验证码&#34;和&#34; captcha_key&#34;在请求中