When making a registration form it is a must for you to create Captcha to avoid robots and any other kind of spams. Well what is Captcha by the way? It is not just a random word or random numbers. It must be image. As a beginner it is very difficult for us to make this kind of Captcha. Thanks for Google for providing recaptcha for free.

Now this is the way on how will you implement recaptcha in your ruby on rails Application.

Step 1.

It’s a must that you have internet connection because Google recaptcha is getting its data online.

Step 2.

You need to add this gem in your gemfile the Google recaptcha will be downloaded and can be used by your application

gem ‘recaptcha’

After adding this file to your gemfile run bundle install. Make sure that you run your server again to use the current changes.

Step 3.

Add this inside your form.

<%=recaptcha_tags%>

Example

  <form action=”#”>

<input type=”text” name=”name”>

<%=recaptcha_tags%>

<input type=”submit” name=”submit” >

</fomr>

Step 4.

To verify if the Captcha is correct you must make a simple if statement like this

if verify_recaptcha #returns true if the Captcha is correct

#do something here

Else

#do something here

end

Now we are done.

It must work perfectly fine.

 

Lastly, please make sure that you have no unclose html tags in a page where you recaptcha tags is because the very_recaptcha might return false.

 

If you have any question please feel free to ask me in the comment I will sure answer your question. Regarding this matter.

Share on Google+Tweet about this on TwitterShare on FacebookShare on TumblrShare on StumbleUponPin on PinterestShare on LinkedInDigg thisShare on RedditEmail this to someone