-
Notifications
You must be signed in to change notification settings - Fork 8
Captcha
JP Barbosa edited this page Jul 23, 2015
·
2 revisions
echo "gem 'recaptcha', require: 'recaptcha/rails'" >> Gemfile
bundle install
nano config/initializers/recaptcha.rb
Recaptcha.configure do |config|
config.public_key = ENV['RECAPTCHA_PUBLIC_KEY']
config.private_key = ENV['RECAPTCHA_PRIVATE_KEY']
config.api_version = 'v2'
end
nano app/views/recommendations/_form.html.erb
<%= simple_form_for([@article, @recommendation]) do |f| %>
<%= f.input :email %>
<%= recaptcha_tags %>
<%= f.button :submit, class: 'btn btn-primary' %>
<% end %>
nano app/controllers/recommendations_controller.rb
...
if @recommendation.valid? && verify_recaptcha(model: @recomendation)...
format.html { redirect_to articles_url, notice: 'Recommendation...' }
format.json { render json: @recomendation }
else
...
rails s
open http://localhost:3000/articles/1/recommendations/new
git add .
git commit -m "Add recaptcha"