# Phone number not coming through: noob

**URL:** <https://www.ruby-forum.com/t/phone-number-not-coming-through-noob/151784>\
**Category:** Rails\
**Created:** [October 25, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/phone-number-not-coming-through-noob/151784 "2008-10-25T17:20:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [October 25, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/phone-number-not-coming-through-noob/151784/1 "2008-10-25T17:20:09Z")

</div>

Hi:

used scaffold to create a phone number table. But when phone number  
saves it’s not coming through as the number entered in the text field:

RESULT FROM DB WHEN I ENTER PHONE NUMBER OF 215 555 1212 INTO WEB  
FORM:

REPLACE INTO “phones” (“id”, “number”, “phone\_type\_id”, “employee\_id”,  
“created\_at”, “updated\_at”) VALUES  
(13,2147483647,1,‘8’,‘2008-10-25 11:05:48’,‘2008-10-25 11:05:48’);

Seems like I’m doing something wrong that the phone number entered  
insn’t coming through as the number. the “2147483647” value is the  
same value that is entered in the DB all the time.

What am I doing wrong? Thanks so much in advance!

All code below:

VIEW:

\<% form\_for(@phone) do |f| %\>

\<%= hidden\_field\_tag :employee\_id, @phone.employee\_id %\>

  
  
  

| Number: | \<%= f.text\_field :number %\> (required - no spaces or dashes) |
| Phone type: | \<%= f.collection\_select(:phone\_type\_id, PhoneType.find(:all), :id, :name) %\> (required) |
| Number: | \<%= text\_field\_tag :number2 %\> (required - no spaces or dashes) |
|   
\<%= link\_to “Cancel”, “/dashboard.html” %\>  
 | \<%= f.submit “Finish \>\>” %\>  
 |

\<% end %\>

CONTROLLER:

def new  
@phone = Phone.new  
if params[:id].nil?  
else  
@emp = Employees.find(params[:id])  
@phone.employee\_id = params[:id]  
end

```
respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @phone }
end

```

end

def create  
@phone = Phone.new(params[:phone])  
@phone.employee\_id = params[:employee\_id]

```
respond_to do |format|
  if @phone.save
    flash[:notice] = 'Phone was successfully created.'
    format.html { redirect_to(@phone) }
    format.xml { render :xml => @phone, :status

```

=\> :created, :location =\> @phone }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @phone.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end

MODEL:

class Phone \< ActiveRecord::Base  
has\_many :phone\_types  
belongs\_to :employees

validates\_presence\_of :number  
validates\_length\_of :number, :maximum =\> 10  
validates\_numericality\_of :number,  
:message =\> “Phone number can be only  
numbers.”  
end

DB MIGRATION:

class CreatePhones \< ActiveRecord::Migration  
def self.up  
create\_table :phones do |t|  
t.integer :number  
t.integer :phone\_type\_id  
t.integer :employee\_id

```
  t.timestamps
end

```

end

def self.down  
drop\_table :phones  
end  
end

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [October 25, 2008, 5:38pm UTC](https://www.ruby-forum.com/t/phone-number-not-coming-through-noob/151784/2 "2008-10-25T17:38:52Z")

</div>

On 25 Oct 2008, at 16:19, Miked wrote:

> Hi:
> 
> used scaffold to create a phone number table. But when phone number  
> saves it’s not coming through as the number entered in the text field:
> 
> RESULT FROM DB WHEN I ENTER PHONE NUMBER OF 215 555 1212 INTO WEB  
> FORM:

You’ve created phone numbers as integer columns. by default the  
database is probably using 32 bits integers which  
2155551212 will overflow and the database stores the maximum possible  
value for such a column instead.  
You could change the column to a larger integer type, but if i were  
you i would change it to a string column and phone numbers are numbers  
in the usual sense (eg the leading 0 in a phone number is significant,  
but an integer column won’t store that)

Fred
