Bas*_*ect 5 controller ruby-on-rails recaptcha ruby-on-rails-plugins ruby-on-rails-3
我在Rails 3上运行了ambethia的reCAPTCHA插件.有谁知道如何覆盖它的flash消息标记?我想重用我自己的flash_errordiv id而不是使用插件的flash_recaptcha_errordiv id:
<div id="flash_recaptcha_error">incorrect-captcha-sol</div>
Run Code Online (Sandbox Code Playgroud)
另外,你如何清理这个控制器#create?
def create
@post = Post.new(params[:post])
respond_to do |format|
if verify_recaptcha(:model => @post, :error => "reCAPTCHA incorrect. Try again.") && @post.save
flash.now[:notice] = "Created \"#{@post.title}\""
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
else
flash.now[:error] = "Incorrect word verification. Are you sure you\'re human?"
format.html { redirect_to(:back, :error => 'reCAPTCHA incorrect. Try again.') }
end
end
end
Run Code Online (Sandbox Code Playgroud)
感谢您阅读我的问题.
因为flash []是一个数组,你可以删除它里面的元素.当我们使用recaptcha gem时,flash数组包含recaptcha_error元素,所以你只需要在控制器中删除这个元素: flash.delete(:recaptcha_error).
例如 :
if verify_recaptcha(:model=>@object,:message=>"Verification code is wrong", :attribute=>"verification code") && @object.save
#your code if succes
else
flash.delete(:recaptcha_error)
#your code if its fail
end
Run Code Online (Sandbox Code Playgroud)
也许它可以帮助你.谢谢
| 归档时间: |
|
| 查看次数: |
1740 次 |
| 最近记录: |