# Active record validation Issue

**URL:** <https://www.ruby-forum.com/t/active-record-validation-issue/183492>\
**Category:** Rails\
**Created:** [February 15, 2010, 2:48pm UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492 "2010-02-15T14:48:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sakhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sakhi](https://www.ruby-forum.com/u/sakhi)\
**Post date:** [February 15, 2010, 2:48pm UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492/1 "2010-02-15T14:48:41Z")

</div>

Hello,

I am trying to put some validation using active records onto form  
fields.  
like this -

validates\_length\_of :tag\_list, :maximum =\> 2

When i provide value of tag\_list as “abc” then it gives the proper  
message  
that length cannot be more than two. And when i provide value of  
tag\_list as  
“abc xyz” then my application accepts the data, which should not happen  
because the complete length of input data is more than 2.  
So i think when i include space in input data then it counts the words  
and  
if space is not there in input than the charcters will be counted.

Could anyone help me out here? Thanks in advance!!

---

<div class="post-metadata">

**Author:** ![sakhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sakhi](https://www.ruby-forum.com/u/sakhi)\
**Post date:** [February 15, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492/2 "2010-02-15T19:19:05Z")

</div>

Are you using the acts\_as\_taggable plugin? 'Cause then tag\_list varies  
between string and array. Don’t know if that’s the case here though.

–Lasse

2010/2/15 Web D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sakhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sakhi](https://www.ruby-forum.com/u/sakhi)\
**Post date:** [February 16, 2010, 6:24am UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492/3 "2010-02-16T06:24:25Z")

</div>

Yes, i am using acts\_as\_taggable plugin. But then what could be the  
solution for this?

---

<div class="post-metadata">

**Author:** ![sakhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sakhi](https://www.ruby-forum.com/u/sakhi)\
**Post date:** [February 17, 2010, 12:16pm UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492/4 "2010-02-17T12:16:55Z")

</div>

Any solution to this???  
I am stuck ☹

---

<div class="post-metadata">

**Author:** ![sakhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sakhi](https://www.ruby-forum.com/u/sakhi)\
**Post date:** [February 17, 2010, 12:34pm UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492/5 "2010-02-17T12:34:39Z")

</div>

What are you trying to validate? That the tag\_list doesn’t contain  
elements longer than 2 charaters?

I reckon you’d have to do the validation manually then

private  
def validate  
#Do some checks on self.tag\_list and if it fails:  
errors.add(:tag\_list, 'cannot contain elements longer than 2  
characters)  
end

---

<div class="post-metadata">

**Author:** ![sakhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sakhi](https://www.ruby-forum.com/u/sakhi)\
**Post date:** [February 17, 2010, 12:23pm UTC](https://www.ruby-forum.com/t/active-record-validation-issue/183492/6 "2010-02-17T12:23:47Z")

</div>

On Feb 17, 11:16 am, Web D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Any solution to this???  
> I am stuck ☹

Well if acts\_as\_taggable behaves as Lasse says then sounds like you  
need to write a custom validation method that checks the various cases  
that can occur. Something like

validates :tags\_long\_enough

def tags\_long\_enough  
if …  
errors.add(:tag\_list, “those tags are not nice”)  
end  
end

would probably do the job

Fred
