出于某种原因,我收到以下错误:
Recaptcha::RecaptchaError in RegistrationsController#create
getaddrinfo: nodename nor servname provided, or not known
def create
if verify_recaptcha <--- this line is causing the error.
resource.save
super
else
build_resource(sign_up_params)
注册控制器:
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
if verify_recaptcha(:model => resource, :message => "Oh! It's error with reCAPTCHA!") && resource.save
super
else
build_resource(sign_up_params)
clean_up_passwords(resource)
flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code."
flash.delete :recaptcha_error
render :new
end
end
protected
def users_steps_path(resource)
'/user_steps'
end
end
registrations / new.html.erb表单
<div class="col-xs-12 col-md-12">
<div class="styled email-input2">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.email_field :email, autofocus: true, placeholder: "Email", class: "email-input" %>
</div>
<div><%= f.text_field :username, autofocus: true, placeholder: "Username", class: "email-input" %>
</div>
<div><%= f.password_field :password, autocomplete: "off", placeholder: "Password", class: "email-input" %>
</div>
<div><%= f.password_field :password_confirmation, autocomplete: "off", placeholder: "Password confirmation", class: "email-input" %>
</div>
<div class="g-recaptcha" data-sitekey="6LeUQ_4SAAAAANicStPQ_OB68A-pr_EN3y3AF5UF"></div>
<div><%= recaptcha_tags %></div>
</div>
<div class="get_motivated2">
<%= f.submit "Sign up", class: "get_motivated btn-danger" %>
<% end %>
</div>
</div>
的routes.rb
devise_for :users, controllers: { registrations: 'registrations' }
API密钥存储在我的shell bash_profile文件中。
这里的任何帮助都会很棒!
P.S。当我访问我的regestrations / new.html.erb页面时,repcatcha没有立即显示,它只在刷新时显示?我们怎样才能立即显示它?
答案 0 :(得分:0)
安装文档提供了一个默认的初始化程序,如下所示:
Recaptcha.configure do |config|
config.public_key = 'XXXXXXXXXXXXXX'
config.private_key = 'XXXXXXXXXXXXXX'
config.proxy = 'http://myproxy.com.au:8080'
end
如果您不使用代理,请删除最后一行:
config.proxy = 'http://myproxy.com.au:8080'