Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
将验证码添加到 Rails 应用程序的最简单方法是使用 Ambethia reCAPTCHA:
1.安装:
如果您愿意,也可以将其作为插件安装。
2.获取 reCAPTCHA 帐户:
您必须创建一个 reCAPTCHA 密钥。您可以在 reCAPTCHA 网站上执行此操作。
3.用法:
使用
recaptcha_tags
输出必要的HTML代码,然后使用verify_recaptcha
验证输入。4.进一步阅读:
The easiest way to add a CAPTCHA to your Rails application is using Ambethia reCAPTCHA:
1. Installation:
You can install it as a plugin, too, if you like.
2. Get a reCAPTCHA account:
You have to create a reCAPTCHA key. You can do it on the reCAPTCHA site.
3. Usage:
Use
recaptcha_tags
to output the necessary HTML code and then verify the input withverify_recaptcha
.4. Further reading:
安装
将以下内容添加到您的 GEMFILE 中
,或者
如果您使用 Bundler(或使用 Rails 配置的包管理器),则运行
bundle install
设置
安装后,请按照以下简单步骤设置插件。设置将取决于您的应用程序使用的 Rails 版本。
使用
基于控制器
在文件“app/controllers/application.rb”中添加以下行
在表单标签内的视图文件中添加此代码
,并在控制器的操作中将其验证为基于
模型
在表单标签内的视图文件中添加此代码代码
并在模型类中添加此代码
FormBuilder helper
Validating with captcha
注意:@user.valid?仍然会正常工作,它不会验证验证码。
使用验证码保存
注意:@user.save 仍将正常工作,它不会验证验证码。
Formtastic 集成
SimpleCaptcha 会检测您是否使用 Formtastic 并附加
选项和选项。示例
视图选项
全局选项
该插件有八种不同的样式可供选择,例如:
默认样式为“simply_blue”。您还可以指定“随机”来选择随机图像样式。
*创建“rails_root/config/initializers/simple_captcha.rb”*
您可以添加自己的样式:
您也可以提供image_magick的安装路径:
您可以提供应存储tmp文件的路径。当您无法访问 /tmp (默认目录)时,它很有用
如何更改 SimpleCaptcha DOM 元素的 CSS?
您可以根据需要在此文件中更改 SimpleCaptcha DOM 元素的 CSS。
*/app/views/simple_captcha/_simple_captcha.erb*
视图示例
基于控制器的示例
基于模型的示例
模型选项
模型示例
Installation
Add the following to your GEMFILE
or
Then run
bundle install
if you're using Bundler (or use the package manager for your Rails configuration)Setup
After installation, follow these simple steps to setup the plugin. The setup will depend on the version of rails your application is using.
Usage
Controller Based
Add the following line in the file “app/controllers/application.rb”
In the view file within the form tags add this code
and in the controller’s action authenticate it as
Model Based
In the view file within the form tags add this code
and in the model class add this code
FormBuilder helper
Validating with captcha
NOTE: @user.valid? will still work as it should, it will not validate the captcha code.
Saving with captcha
NOTE: @user.save will still work as it should, it will not validate the captcha code.
Formtastic integration
SimpleCaptcha detects if your use Formtastic and appends
Options & Examples
View Options
Global options
There are eight different styles available with the plugin as…
Default style is ‘simply_blue’. You can also specify ‘random’ to select the random image style.
*Create “rails_root/config/initializers/simple_captcha.rb”*
You can add your own style:
You can provide the path where image_magick is installed as well:
You can provide the path where should be stored tmp files. It’s usefull when you dont have acces to /tmp (default directory)
How to change the CSS for SimpleCaptcha DOM elements?
You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file.
*/app/views/simple_captcha/_simple_captcha.erb*
View’s Examples
Controller Based Example
Model Based Example
Model Options
Model’s Example
嗯,ReCaptcha 可以完成这项工作,并且网上有很多关于它的教程。
但是,您必须在控制器中编写正确的“def create”(创建方法),该控制器将传递表单中的任何内容并同时验证 Recaptcha。然后它就会很好地工作。
有一个小问题。将 ReCaptcha 插入表单后,表单验证停止工作。但是,可以通过插入模型文件中的简单代码来修复它:(
:create = 是控制器中的“def create”方法)。它将强制表单首先验证表单,然后验证 Recaptcha。
Well, ReCaptcha will do the job and there are many tutorials on it online.
However, you have to write a correct "def create" (create method) in your controller that will pass whatever is in your form plus validate Recaptcha at the same time. Then it will work nicely.
There was one little problem with it. After I inserted ReCaptcha into my form, the form validation stopped working. However, it can be fixed with an easy code inserted into the model file:
(:create = is the "def create" method in your controller). It will force the form to validate the form first and then validate Recaptcha.
我在我的 PHP 项目之一中使用了 Recaptcha。 http://recaptcha.net/
据该网站称,它还有 Ruby 插件 (http://recaptcha.net/resources.html)。虽然第一个 ruby 链接不起作用,但下一个链接仍然有效。 http://svn.ambethia.com/pub/rails/plugins/recaptcha/< /a>
检查一下。
I've used Recaptcha in one of my PHP project. http://recaptcha.net/
According to the site, it also has plugins for Ruby (http://recaptcha.net/resources.html). Although first ruby link didn't work, next link still works. http://svn.ambethia.com/pub/rails/plugins/recaptcha/
Check it.
我已经使用 ambethia recapchat 进行 Rails 应用程序。它比其他的最容易
I've used ambethia recapchat for rails application. it most easy than other
就功能而言,用于 Rails 的 reCAPTCHA 非常棒。但是,如果您需要 XHTML 验证,请远离!该插件不会(并且可能永远不会)验证。我觉得很尴尬的是,我的整个网站上只有一个页面没有验证 - 这是带有 reCAPTCHA 的页面。如果有其他选择,我会选择。
reCAPTCHA for rails is great, in terms of functionality. However, if you require XHTML validation, RUN AWAY! This plugin does not (and probably never will) validate. I find it embarrassing that only one page on my entire site does not validate - it is the page with reCAPTCHA. If there was ANY other choice, I would take it.
如果您正在寻找可验证的验证码,并且(几乎)与 reCAPTCHA 一样易于使用,请尝试我的 SlideCAPTCHA。 (几天前写的,需要在实际使用中进行一些测试。)我的部署过程基于 reCAPTCHA 插件,但您可以使用 CSS 对其进行样式设置。
然而,它确实需要 Ruby/GD,所以如果您还没有 GD,我不能保证 GD 易于安装和使用!
if you're after a CAPTCHA that validates, and is (almost) as easy to use as reCAPTCHA, please give my SlideCAPTCHA a try. (Wrote it a few days ago, needs some tests in real-life usage.) I based its deployment process on the reCAPTCHA plugin, but you can style it with CSS.
It does require Ruby/GD, however, so if you don't have GD already, I can't promise that GD is easy to install and use!