rails添加验证码
1.安装包
gem 'rucaptcha'
gem 'dalli'
2.配置路由
mount RuCaptcha::Engine => "/rucaptcha"
3 controller部分
def create
@user = User.new(user_params)
if verify_rucaptcha?(@user)&&@user.save
......
4.view部分
<div class="form-group ">
<%= rucaptcha_input_tag( placeholder: '输入验证码') %>
<%= rucaptcha_image_tag(class:'image-box', alt: 'Captcha') %>
</div>
5 . 实现点击图片刷新验证码
<script type="text/javascript">
$(".image-box").click(function(){
var src=$(".image-box").attr("src");
$(".image-box").attr("src",src.split("?")[0]+"?"+(new Date().getTime()))
})
</script>
梦里不知身是客,一晌贪欢。