2014-02-12 2 views
0

작은 세부 사항을 놓친 것 같은 느낌이지만 이해할 수 있습니다.레일 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 

답변

2

이 보석은 레일을 레일 4 4. 작업 보석 지원하지 : 보안 문자 텍스트없이

가 제대로 저장되어, 그것은 작동 https://github.com/pludoni/simple-captcha

을 그리고 코드에서 많은 오해입니다

def create 
    @test = Test.new(captcha_params) 

    if @test.save_with_captcha 
     redirect_to root_path 
    else 
     if @test.errors.any? 
     redirect_to tests_path 
     end 
    end 
    end 

    private 
    def captcha_params 
    params.require(:test).permit(:id, :text, :captcha, :captcha_key) 
    end 
관련 문제