0

我想在我的表单中添加简单的术语验证器:

模型

attr_accessor :terms
validates :terms, :acceptance => {:accept => true}, :allow_nil => false

查看(simple_form)

= simple_form_for @student, html: { multipart: true } do |f|
   ...
= f.input :terms, as: :select
= f.button :submit

但我得到:

Can't mass-assign protected attributes: terms

我做错了什么?

4

2 回答 2

1

您可以尝试:

field :terms, :type => Boolean, :default => false
attr_accessible :terms
validates :terms, :acceptance => {:accept => true}

在你看来:

<%= f.input :agree, :as => :boolean, label: false %> 

问候!

于 2013-01-21T22:21:18.877 回答
0

您不需要列或attr_accessor它,否则它将是一个类对象。

你能做的是

attr_accessible :terms
validates_acceptance_of :terms

<%= f.check_box :terms%> I agree to ....
于 2013-01-21T22:19:12.907 回答