【问题标题】:Rails simple captcha attributesRails 简单的验证码属性
【发布时间】:2014-03-11 13:23:06
【问题描述】:

当我在我的 rails 3 项目 gem "simple-captcha" (https://github.com/galetahub/simple-captcha) 中使用时,我通过调用函数 看到了错误:

Can't mass-assign protected attributes: key

【问题讨论】:

    标签: ruby-on-rails-3 simplecaptcha


    【解决方案1】:

    这对我有用:

    将其放入初始化程序 (config/initializers/simple_captcha.rb)

    Rails.configuration.to_prepare do
      class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
        attr_protected
      end
    end
    

    【讨论】:

      【解决方案2】:

      我收到此错误是因为我使用的是基于表单的视图代码:

      <%= f.simple_captcha(:label => "Enter letters from image above", :placeholder => "") %>
      

      我认为这是由 f 引用我的用户模型引起的,这可能 不引用验证码属性。我放弃了表格基础和问题 离开了。 (尝试了上述两种解决方案,但在我的情况下它们都不起作用。):

      <%= show_simple_captcha(:label => "Enter letters from image above",
                              :placeholder => "") %>
      

      【讨论】:

        【解决方案3】:

        解决方案: 通过

        为rails 3应用程序使用替代存储库
        gem 'simple_captcha', :git => 'git://github.com/rubymaniac/simple-captcha'
        

        【讨论】:

          猜你喜欢
          • 2014-04-15
          • 2011-06-15
          • 2013-05-19
          • 2015-04-20
          • 2014-09-20
          • 1970-01-01
          • 2013-03-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多