# Form removing leading zeros for a string

**URL:** <https://www.ruby-forum.com/t/form-removing-leading-zeros-for-a-string/117583>\
**Category:** Rails\
**Created:** [October 18, 2007, 10:14am UTC](https://www.ruby-forum.com/t/form-removing-leading-zeros-for-a-string/117583 "2007-10-18T10:14:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [October 18, 2007, 10:14am UTC](https://www.ruby-forum.com/t/form-removing-leading-zeros-for-a-string/117583/1 "2007-10-18T10:14:08Z")

</div>

Hi,

I have a drop down select see below which populates from the below,

select(:record, :visually\_similar\_to, Sample.find(:all).collect {|p|  
p.sample\_ref, p.id ] })

sample\_ref is varchar field so the values that populate the drop down  
are below and they include the leading zeros

0003  
0004  
0005  
etc…

When i save this record the field is called visually\_similar\_to this  
removes the leading zeros and leaves it with just the 3 or 4 etc

Why is it removing the leading zeros if its saving to a string field,  
how can i stop this. I dont always know how many characters will be in  
the field so i couldnt just count the number of characters and then add  
the missing zero’s, this shouldnt be neccessary anyway because its a  
string field?

Can anyone help?

JB

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [October 18, 2007, 11:31am UTC](https://www.ruby-forum.com/t/form-removing-leading-zeros-for-a-string/117583/2 "2007-10-18T11:31:35Z")

</div>

Sorry for the stupid question, its saving the id and not the sample\_ref  
field, doh! I need a day off!

JB
