# setting blanks

**URL:** <https://discuss.rubyonrails.org/t/setting-blanks/24578>\
**Category:** rubyonrails-talk\
**Created:** [February 8, 2008, 3:51pm UTC](https://discuss.rubyonrails.org/t/setting-blanks/24578 "2008-02-08T15:51:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 8, 2008, 3:51pm UTC](https://discuss.rubyonrails.org/t/setting-blanks/24578/1 "2008-02-08T15:51:20Z")

</div>

I have this form which has a whole bunch of stuff for a user to fill out, not all of the fields have to be filled, but the one that are left blank I need to enter a dummie value for in the database because all that stuff gets entered later on into another form consisting of edit\_in\_place fields. The way I have it now is that a method gets called after a user profile is created and sets all the values to a dummie string if they are blank, the problems is that there are so many field in the table that the method is very long because of all the fields. Bacisally I'm saying if

if @user.address.blank? &nbsp;&nbsp;@user.address = "Empty"

Is there a way to do this which isn't as long and maybe more programmatically correct? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 8, 2008, 4:13pm UTC](https://discuss.rubyonrails.org/t/setting-blanks/24578/2 "2008-02-08T16:13:23Z")

</div>

i think validates\_each should be, what you're looking for:

[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001324](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001324)

something on that line:

validates\_each :email, :phone, :on =\> :create do |record, attr, value| if value.blank? ... end

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 8, 2008, 9:09pm UTC](https://discuss.rubyonrails.org/t/setting-blanks/24578/3 "2008-02-08T21:09:30Z")

</div>

Thorsten Mueller wrote:

> validates\_each :email, :phone, :on =\> :create do |record, attr, value| if value.blank? ... end

I think you are correct and that this is exactly what I want, but it doesn't save the values when I create a new object. I have a model for user and am trying to save stuff on save. Here is what I got:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validates\_each :company, :on =\> :save do|record, attr, value| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if value.blank? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr = "Click to Edit" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

I tried to say record.attr = "Click to Edit" but that didn't seem to work. When I create a new user it seems to run through the whole process - the validates\_each too, but it doesn't save. Is there something that I'm missing? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![brewpoo](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@brewpoo](https://discuss.rubyonrails.org/u/brewpoo)\
**Post date:** [February 8, 2008, 9:33pm UTC](https://discuss.rubyonrails.org/t/setting-blanks/24578/4 "2008-02-08T21:33:19Z")

</div>

Why does the value need to be in the database? Why not override the display of the column for empty? have it output what every you want.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 8, 2008, 9:43pm UTC](https://discuss.rubyonrails.org/t/setting-blanks/24578/5 "2008-02-08T21:43:35Z")

</div>

brewpoo wrote:

> Why does the value need to be in the database? Why not override the display of the column for empty? have it output what every you want.
> 
> On Feb 8, 4:09 pm, Shandy Nantz \<rails-mailing-l...@andreas-s.net\>

Because later on in another part of the form I display the values in in\_place\_edit fields and if the values are empty strings then I can't edit the values by clicking on them because there is nothing to click on.

-S
