Hi All,
For some reason, when I have validates_acceptance_of on a checkbox, it
works for validation, but it isn''t saving the ''1''
(indicating
acceptance) into the field of the database - it leaves it as NULL.
If I take the validation off, it saves it as a ''1''.
I am validating a simple check box for a legal agreement, and we have to
save in the database that they accepted the agreement...
My validation:
(in the model):
validates_acceptance_of :legal_agreement
The view:
<% form_for :enrollment, :url => { :action =>
''validate'', :id =>
params[:id] } do |f| %>
##bunch of form helpers
<p><%= f.check_box :legal_agreement %>
<label for="enrollment_legal_agreement">Legal Acceptance /
Signature</label></p>
<% end %>
Any idears?
Thanks!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Dustin Anderson wrote:> Hi All, > > For some reason, when I have validates_acceptance_of on a checkbox, it > works for validation, but it isn''t saving the ''1'' (indicating > acceptance) into the field of the database - it leaves it as NULL. > > If I take the validation off, it saves it as a ''1''. > > I am validating a simple check box for a legal agreement, and we have to > save in the database that they accepted the agreement... > > My validation: > (in the model): > validates_acceptance_of :legal_agreement >The documentation only says that :terms_of_service is a virtual attribute and is not saved to the database. But your attribute is not called that, it''s called legal_agreement. I just tried it myself, and it seems that when validates_acceptance_of is used with any column, a NULL is inserted into that column (which violates my not null constraint). Must be a bug? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
validates_acceptance_of is for virtual (non-database-backed) attributes. If
you want a database record of the agreement having been accepted, just make
legal_agreement a boolean database field and then validate that
legal_agreement == 1.
From the Rails API:
Encapsulates the pattern of wanting to validate the acceptance of a terms of
service check box (or similar agreement). Example:
class Person < ActiveRecord::Base
validates_acceptance_of :terms_of_service
validates_acceptance_of :eula, :message => "must be abided"
end
The terms_of_service attribute is entirely virtual. No database column is
needed. This check is performed only if terms_of_service is not nil and by
default on save.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---