Reputation: 2927
I am following the this to implement captcha, but I am stuck at last step. Here is my controller:
bug_report = BugReport.new(bug_report_params)
if verify_recaptcha
if bug_report.valid?
bug_report.save!
#render success
else
#throw error
end
else
#Invalid captcha
end
I am getting error saying: undefined local variable or method verify_recaptcha
Other codes are here:
<%= form_for :bug_report, url: bug_reports_path do |f| %>
<%= recaptcha_tags %>
<%= f.submit 'Submit' %>
<% end %>
gem "recaptcha", :require => "recaptcha/rails"
Recaptcha.configure do |config|
config.public_key = 'publik_key_here'
config.private_key = 'private_key_here'
end
I am getting the following data in params:
{
utf8: "✓",
g-recaptcha-response: "Long text here",
commit: "Submit",
controller: "api/v1/bug_reports",
action: "index"
}
Please guide me, how to fix it.
Upvotes: 0
Views: 1275
Reputation: 1245
From your comments, It looks like you have the rails app with config.api_only = true
set in application.rb
. For a list of what it actually does, check this documentation.
One consequence of this is ApplicationController
would inherit from ActionController::API
instead of ActionController::Base
. But if you look at recaptcha's source code, the include is on ActionController::Base
.
So, you can directly include Recaptcha::Verify
module in your ApplicationController
.
# app/controllers/application_controller.rb
class ApplicationController < ActionController::API
include Recaptcha::Verify
...
end
Upvotes: 2