The problem is that the simple_captcha is not working properly. The captcha image is not showing. Please help.
if simple_captcha_valid?
do something
else
do something else
end
<div class="captcha">
<%= show_simple_captcha(label: "", placeholder: "", code_type: "numeric") %>
</div>
gem 'simple_captcha2', require: 'simple_captcha'
SimpleCaptcha::SimpleCaptchaData Load (1.3ms) SELECT "simple_captcha_data".* FROM "simple_captcha_data" WHERE "simple_captcha_data"."key" = '******' ORDER BY "simple_captcha_data"."id" ASC LIMIT 1
**WARNING: Can't mass-assign protected attributes for SimpleCaptcha::SimpleCaptchaData: key**
I have the same problem (with Rails 3). But resolve it by adding
attr_accessible :key, :value
where, in my case, simple_captcha_gem_dir is ~/.rvm/gems/ruby-1.9.3-p484/bundler/gems/simple-captcha-2602bf19a63d
(of course for production you can create a fork instead of edit local gem files)
Here is another solution:
Put this in an initializer (config/initializers/simple_captcha.rb
)
Rails.configuration.to_prepare do
class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
attr_protected
end
end
Thanks to @zealot128
Looking at your call <%= show_simple_captcha(:label => "", :placeholder => "", :code_type => "numeric") %>
it seems like you're using controller based implementation of simple_captcha
I don't see your ApplicationController
code but make sure the following lines are present in app/controllers/application.rb
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerHelpers
end
UPDATE Model's Example:
class User < ActiveRecord::Base
apply_simple_captcha
end
class User < ActiveRecord::Base
apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
end
I had the same problem with Rails 4.1.4, Ruby 2.1.2 I used the config below in simple_captcha.rb
Rails.configuration.to_prepare do
class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
attr_protected :captcha, :captcha_key
end
end
but...
As I noticed in simple captcha controller in .rvm/gems/bundler
, captcha key/value is passed via params[:captcha_key] and params[:captcha] which impose the problem because in view I used
<%= f.simple_captcha :label => "Enter numbers.." %>
in which params are passed via params[:MODEL][:captcha]
so... for now I just added a set_captcha action in controller to set
params[:captcha] = params[:MODEL][:captcha]
params[:captcha_key] = params[:MODEL][:captcha_key]
I'm looking for a better solution, any idea?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With