railsfid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Dec-03 00:12 UTC
validates acceptance of question
I have a terms of service agreement attached to a checkbox. It seems to work ok and I see "agreement"=>"0" when the box is not checked in the development log and "agreement"=>"1" when the box is checked in the log. But in the model I this validation: validates_acceptance_of :agreement, :message => "Please accept the terms to proceed" So when the form is actually filled out, no matter whether the box is checked or not I get: 1 error prohibited this agent from being saved There were problems with the following fields: -Agreement, Please accept the terms to proceed So what am I missing to get this to work? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I have a terms of service agreement attached to a checkbox. It seems > to work ok and I see > > "agreement"=>"0" when the box is not checked in the development log > > and > > "agreement"=>"1" when the box is checked in the log. > > But in the model I this validation: > > validates_acceptance_of :agreement, > :message => "Please accept the terms to > proceed" > > > So when the form is actually filled out, no matter whether the box is > checked or not I get: > > 1 error prohibited this agent from being saved > > There were problems with the following fields: > > -Agreement, Please accept the terms to proceed > > > So what am I missing to get this to work?is :agreement a field in your database? if so the docs say... :accept - Specifies value that is considered accepted. The default value is a string "1", which makes it easy to relate to an HTML checkbox. This should be set to true if you are validating a database column, since the attribute is typecast from "1" to true before validation. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
railsfid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Dec-03 06:05 UTC
Re: validates acceptance of question
Yes, :agreement is a field in my database. Should I remove it? In any case I did set the :accept => "true", but it didn''t change anything. I get the same error when I submit the form whether or not the box is checked. The html shows: <ul><div class="fieldWithErrors"><input checked="checked" id="agent_agreement" name="agent[agreement]" type="checkbox" value="1" /></div><div class="fieldWithErrors"><input name="agent [agreement]" type="hidden" value="0" /></div> Am I reading this right that after the checkbox value is set to "1" that then there is a hidden value that is setting it to "0"? Is this supposed to be this way? On Dec 2, 7:26 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > I have a terms of service agreement attached to a checkbox. It seems > > to work ok and I see > > > "agreement"=>"0" when the box is not checked in the development log > > > and > > > "agreement"=>"1" when the box is checked in the log. > > > But in the model I this validation: > > > validates_acceptance_of :agreement, > > :message => "Please accept the terms to > > proceed" > > > So when the form is actually filled out, no matter whether the box is > > checked or not I get: > > > 1 error prohibited this agent from being saved > > > There were problems with the following fields: > > > -Agreement, Please accept the terms to proceed > > > So what am I missing to get this to work? > > is :agreement a field in your database? if so the docs say... > > :accept - Specifies value that is considered accepted. The default > value is a string "1", which makes it easy to relate to an HTML > checkbox. This should be set to true if you are validating a database > column, since the attribute is typecast from "1" to true before > validation.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 2, 2008, at 10:05 PM, railsfid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Yes, :agreement is a field in my database. Should I remove it? > In any case I did set the :accept => "true", but it didn''t change > anything. I get the same error when I submit the form whether or not > the box is checked.Set :accept => true (no quotes). That''s how I read the docs... if it''s a database column, you need that.> The html shows: > > <ul><div class="fieldWithErrors"><input checked="checked" > id="agent_agreement" name="agent[agreement]" type="checkbox" > value="1" /></div><div class="fieldWithErrors"><input name="agent > [agreement]" type="hidden" value="0" /></div> > > Am I reading this right that after the checkbox value is set to "1" > that then there is a hidden value that is setting it to "0"? Is this > supposed to be this way? > > > > > On Dec 2, 7:26 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: >>> I have a terms of service agreement attached to a checkbox. It seems >>> to work ok and I see >> >>> "agreement"=>"0" when the box is not checked in the development >>> log >> >>> and >> >>> "agreement"=>"1" when the box is checked in the log. >> >>> But in the model I this validation: >> >>> validates_acceptance_of :agreement, >>> :message => "Please accept the terms to >>> proceed" >> >>> So when the form is actually filled out, no matter whether the box >>> is >>> checked or not I get: >> >>> 1 error prohibited this agent from being saved >> >>> There were problems with the following fields: >> >>> -Agreement, Please accept the terms to proceed >> >>> So what am I missing to get this to work? >> >> is :agreement a field in your database? if so the docs say... >> >> :accept - Specifies value that is considered accepted. The default >> value is a string "1", which makes it easy to relate to an HTML >> checkbox. This should be set to true if you are validating a database >> column, since the attribute is typecast from "1" to true before >> validation. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
railsfid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Dec-04 00:42 UTC
Re: validates acceptance of question
Thanks for your help. That was it. Remove the quotes and it works. On Dec 3, 9:36 am, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Dec 2, 2008, at 10:05 PM, rails...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > > > Yes, :agreement is a field in my database. Should I remove it? > > In any case I did set the :accept => "true", but it didn''t change > > anything. I get the same error when I submit the form whether or not > > the box is checked. > > Set :accept => true (no quotes). That''s how I read the docs... if > it''s a database column, you need that. > > > The html shows: > > > <ul><div class="fieldWithErrors"><input checked="checked" > > id="agent_agreement" name="agent[agreement]" type="checkbox" > > value="1" /></div><div class="fieldWithErrors"><input name="agent > > [agreement]" type="hidden" value="0" /></div> > > > Am I reading this right that after the checkbox value is set to "1" > > that then there is a hidden value that is setting it to "0"? Is this > > supposed to be this way? > > > On Dec 2, 7:26 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > >>> I have a terms of service agreement attached to a checkbox. It seems > >>> to work ok and I see > > >>> "agreement"=>"0" when the box is not checked in the development > >>> log > > >>> and > > >>> "agreement"=>"1" when the box is checked in the log. > > >>> But in the model I this validation: > > >>> validates_acceptance_of :agreement, > >>> :message => "Please accept the terms to > >>> proceed" > > >>> So when the form is actually filled out, no matter whether the box > >>> is > >>> checked or not I get: > > >>> 1 error prohibited this agent from being saved > > >>> There were problems with the following fields: > > >>> -Agreement, Please accept the terms to proceed > > >>> So what am I missing to get this to work? > > >> is :agreement a field in your database? if so the docs say... > > >> :accept - Specifies value that is considered accepted. The default > >> value is a string "1", which makes it easy to relate to an HTML > >> checkbox. This should be set to true if you are validating a database > >> column, since the attribute is typecast from "1" to true before > >> validation.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---