The step to create Ruby on Rails Application with reCAPTCHA
Initial steps to take
By using Rails Scaffold we can generate some of the major pieces of an application. Using scaffold in a single operation we can create the models, views, and controllers and resources for our application.
1. The first Step we required to create the Rails Application.
7. Start the web server:
By using Rails Scaffold we can generate some of the major pieces of an application. Using scaffold in a single operation we can create the models, views, and controllers and resources for our application.
1. The first Step we required to create the Rails Application.
$ rails new SampleApplreCapcha
2. By using the scaffold we will generate the the MVC components needed for Simple Signup form
$ cd SampleApplreCapcha$ rails generate scaffold signup name:string password:string email:string comments:text
3. Create the Signup database table:
$ rake db:create
$ rake db:migrate
Rails uses rake commands to run migrations. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations.
4. Then we need to set routes of our application.
$ rake routes Prefix Verb URI Pattern Controller#Action signups GET /signups(.:format) signups#index POST /signups(.:format) signups#create new_signup GET /signups/new(.:format) signups#new edit_signup GET /signups/:id/edit(.:format) signups#edit signup GET /signups/:id(.:format) signups#show PATCH /signups/:id(.:format) signups#update PUT /signups/:id(.:format) signups#update DELETE /signups/:id(.:format) signups#destroy
5. In the routes.rb file then we will set the routes of our application.
Rails.application.routes.draw do
resources :signups
root 'signups#new'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
6. For adding the reCAPTCHA in the signup form we need to follow some steps.
a) We need to goto to the link https://www.google.com/recaptcha/intro/android.html
and we need to click on get reCAPTCHA icon from top right corner.
b) We need to select the type of recaptcha(we will select reCAPTCHA v2).
c) Then enter the domain name(localhost, myschool etc).
d) Then complete the form and submit the form.
e) Then we will redirected to a page there we will get the code snippet for recaptcha.
f) Paste
this snippet before the closing </head> tag on your HTML
template:
<script src='https://www.google.com/recaptcha/api.js'></script>
g) Paste
this snippet at the end of the <form> where you want the
reCAPTCHA widget to appear in
your form:
<div class="g-recaptcha" data-sitekey="6LeFOzIUAAAAAMSupHi8wWimOLqUtPsb3LEOZO_e"></div>
7. Start the web server:
$ rails server/s
Thsnkd
DeleteThis comment has been removed by the author.
ReplyDeleteThanks sir
ReplyDeleteI am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. 2captcha
ReplyDelete