表格接受条款未经过验证

时间:2017-02-09 20:34:59

标签: ruby-on-rails validation

如果"接受条款"我想归档注册表单给出验证错误。未选中复选框。由于某种原因,所有字段的验证消息都正确显示,但不适用于该复选框。

用户/ new.html.erb:

class User < ActiveRecord::Base

      validates :name,  presence: true, length: { maximum: 50 }
      validates :password, presence: true, length: { minimum: 6 }, allow_nil: true

      # this is the validation
      validates :agreement, acceptance: { accept: true }

...
end

模型/ user.rb:

    string result = "-1";

    DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", "localhost"));

    foreach (DirectoryEntry site in w3svc.Children)
    {
        if (site.Properties["ServerComment"] != null)
        {
            if (site.Properties["ServerComment"].Value != null)
            {
                if (string.Compare(site.Properties["ServerComment"].Value.ToString(),

                                        "website.com", true) == 0)
                {
                    result = site.Name;
                    break;

                }
            }
        }
    }

    return result;

1 个答案:

答案 0 :(得分:0)

看看这里:http://guides.rubyonrails.org/active_record_validations.html#acceptance

validates :agreement, acceptance: true

应该为你做的伎俩。