0
我觉得我错过了一些小细节,但我可以理解这一点。Rails 4 simple_captcha不工作
我想为他们的项目连接simple_captcha(https://github.com/galetahub/simple-captcha)on Rails的4:
的Gemfile:
gem 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git'
application_controller.rb:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SimpleCaptcha::ControllerHelpers
end
.html.erb:
<%= form_for :test, url: tests_path do |f| %>
...
<p>
<%= f.simple_captcha :label => "Enter numbers..", :object => "test" %>
<%= f.submit %>
</p>
<% end %>
tests_controller.rb:
class TestsController < ApplicationController
...
def create
@test = Test.new(test_params)
if @test.valid_with_captcha?
@test.save_with_captcha
redirect_to root_path
else
redirect_to tests_path
end
end
end
轨产生simple_captcha和耙分贝:迁移没有任何错误。
验证码显示,但没有显示自己:没有关系正确输入验证码或不是,仍然重定向到tests_path并且文本不被保留。
没有验证码文本存放不当,它的工作原理:
def create
@test = Test.new(test_params)
@test.save
redirect_to root_path
end
end