# A problem with before\_create and validations

**URL:** <https://www.ruby-forum.com/t/a-problem-with-before-create-and-validations/128618>\
**Category:** Rails\
**Created:** [February 9, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/a-problem-with-before-create-and-validations/128618 "2008-02-09T13:23:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![threeeyedfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@threeeyedfish](https://www.ruby-forum.com/u/threeeyedfish)\
**Post date:** [February 9, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/a-problem-with-before-create-and-validations/128618/1 "2008-02-09T13:23:55Z")

</div>

I stumble across some strange problem.

I have a model with a virtual attribute file\_contents that is a string.  
The model has validates\_format\_of :file\_contents, :on =\> create, :unless  
=\> no\_contents? (The method that returns file\_contents.nil?)  
Then, I have a before\_create callback, where I get my model’s title and  
description by parsing file\_contents, and do write\_attribute for title  
and description.  
The problem is, that it hangs the server. Forever. Looks like  
write\_attribute triggers validation again, and then before\_create is  
called again, and we get an infinite loop.  
I’ve almost broke my brains but still hadn’t found a viable soultion.  
Please, help with whatever you can!

Yours,  
Damian
