我想在我的表单中添加简单的术语验证器:
型
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
我做错了什么?
你可以试试:
field :terms, :type => Boolean, :default => false
attr_accessible :terms
validates :terms, :acceptance => {:accept => true}
在您看来:
<%= f.input :agree, :as => :boolean, label: false %>
问候!
你不需要列或attr_accessor
,否则它将是一个类对象。
你能做的是
attr_accessible :terms
validates_acceptance_of :terms
<%= f.check_box :terms%> I agree to ....