Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails SimpleCaptcha映像未加载(可以大规模分配受保护的属性)_Ruby On Rails_Ruby On Rails 4_Simplecaptcha - Fatal编程技术网

Ruby on rails SimpleCaptcha映像未加载(可以大规模分配受保护的属性)

Ruby on rails SimpleCaptcha映像未加载(可以大规模分配受保护的属性),ruby-on-rails,ruby-on-rails-4,simplecaptcha,Ruby On Rails,Ruby On Rails 4,Simplecaptcha,问题是机器工作不正常。验证码图像未显示。请帮忙 controller.rb view.html.rb 错误 查看您的调用,:placeholder=>,:code\u type=>“numeric”)%>似乎您正在使用基于控制器的简单验证码实现 我看不到您的ApplicationController代码,但请确保app/controllers/application.rb中存在以下行 ApplicationController < ActionController::Base incl

问题是机器工作不正常。验证码图像未显示。请帮忙

controller.rb view.html.rb 错误
查看您的调用
,:placeholder=>,:code\u type=>“numeric”)%>
似乎您正在使用基于控制器的简单验证码实现

我看不到您的
ApplicationController
代码,但请确保
app/controllers/application.rb中存在以下行

ApplicationController < ActionController::Base
  include SimpleCaptcha::ControllerHelpers
end
Rails.configuration.to_prepare do
  class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
    attr_protected
  end
end
ApplicationController
更新模型示例:

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
class用户“机密图像和代码不同”,:add_to_base=>true
结束
我也有同样的问题(Rails 3)。但通过添加

simple\u captcha\u gem\u dir/lib/simple\u captcha/simple\u captcha\u data.rb 在我的例子中,simple\u captcha\u gem\u dir~/.rvm/gems/ruby-1.9.3-p484/bundler/gems/simple-captcha-2602bf19a63d

(当然,对于生产,您可以创建fork而不是编辑本地gem文件)

这里是另一个解决方案:

将其放入初始值设定项(
config/initializers/simple\u captcha.rb

Rails.configuration.to\u prepare do
类SimpleCaptcha::SimpleCaptchaData<::ActiveRecord::Base
属性保护
结束
结束

多亏了

我在Rails 4.1.4和Ruby 2.1.2上也遇到了同样的问题 我在simple_captcha.rb中使用了下面的配置

Rails.configuration.to_prepare do
  class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
    attr_protected :captcha, :captcha_key
  end
end
通过
params[:MODEL][:captcha]

所以。。。 现在我只是在控制器中添加了一个set_验证码动作来设置

params[:captcha] = params[:MODEL][:captcha]
params[:captcha_key] = params[:MODEL][:captcha_key]

我正在寻找更好的解决方案,有什么想法吗?

您是否完成了github上描述的所有步骤?是的,我完成了,没有错误。得到了相同的错误。也许当我捆绑更新时。在哪种型号?还有要补充的内容。attr\u accessible:[在这里写什么]以及在哪里写这行,在哪个模型中。我以为您使用的是Rails 3版本,建议在模型中添加
attr\u accessible
接受嵌套的属性。但是,看起来您已经迁移到Rails 4了。如果你能分享这个模型就太好了。请参阅我的更新答案。是的,包含部分在那里。假设我正在为用户注册实现captcha,在哪里添加attr_accessible(在用户模型或任何其他模型中)。谢谢。请在答案中查看我的更新。您使用的是Rails 3还是Rails 4<随着强参数的引入,Rails 4中不再需要code>attr_accessible
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
attr_accessible :key, :value
Rails.configuration.to_prepare do
  class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
    attr_protected
  end
end
Rails.configuration.to_prepare do
  class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
    attr_protected :captcha, :captcha_key
  end
end
<%= f.simple_captcha :label => "Enter numbers.." %> 
params[:captcha] = params[:MODEL][:captcha]
params[:captcha_key] = params[:MODEL][:captcha_key]