작은 세부 사항을 놓친 것 같은 느낌이지만 이해할 수 있습니다.레일 4 simple_captcha가 작동하지 않음
레일에내가 그들의 프로젝트에 대한 simple_captcha (https://github.com/galetahub/simple-captcha)를 연결하기 위해 노력하고있어 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 및 레이크 DB를 생성한다.
captcha가 표시되지만 자체를 나타내지는 않습니다. captcha가 올바르게 입력되었는지 여부는 중요하지 않으며 tests_path으로 리디렉션되며 텍스트는 보존되지 않습니다. 그것을 알고 보니
def create
@test = Test.new(test_params)
@test.save
redirect_to root_path
end
end