I am trying to add gem recaptcha to my app but I got this error No site key specified
. There is no answer in stack overflow solve mine.
Here is my codes in gem file
gem "recaptcha", require: "recaptcha/rails"
in the question new form
<%= form_for @question do |f| %>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<%= f.text_field :first_name,:required => true ,placeholder: "First Name"%>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<%= f.text_field :last_name,placeholder: "Last Name" %>
</div>
</div>
<%= f.text_field :email ,:required => true ,placeholder: "Email"%>
<%= f.text_area :description ,:required => true ,placeholder: "Questions or Comments",rows: "4" ,cols: "50"%><br>
<%= recaptcha_tags %>
<%= f.submit "SEND My Message" ,class: "btn btn-danger" %>
<% end %>
in question controller
class QuestionsController < ApplicationController
before_action :find_question, only: [:destroy]
def index
@questions = Question.order("updated_at DESC")
end
def create
@question = Question.new(question_attributes)
if verify_recaptcha(model: @user) && @question.save
ContactMailer.message_send(@question).deliver
redirect_to new_question_path, notice: "Thank you... Your message was created successfully."
else
flash.now[:error] = "Please correct the form"
render :new
end
end
def show
@question = Question.find(params[:id])
end
def new
@question=Question.new
end
def destroy
if @question.destroy
redirect_to questions_path, notice: "Message deleted successfully."
else
redirect_to question_path, error: "We had trouble deleting."
end
end
private
def question_attributes
question_attributes = params.require(:question).permit([:first_name,:last_name,:email, :description])
end
def find_question
@question = Question.find(params[:id])
end
end
recaptch.env inside the root file
export RECAPTCHA_SITE_KEY= xxxxxxxxxx
export RECAPTCHA_SECRET_KEY= xxxxxxxxx
Recaptcha.configure do |config|
config.site_key = XXXX
config.secret_key = XXX
end