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| %>
<table width="600" border="0">
    <tr>
        <td class="label">Number:
        </td>
        <td><%= f.text_field :number %> (required - no spaces or
dashes)
        </td>
    </tr>
    <tr>
        <td class="label">Phone type:
        </td>
        <td><%= f.collection_select(:phone_type_id,
PhoneType.find(:all), :id, :name) %> (required)
        </td>
    </tr>
    <tr>
        <td class="label">Number:
        </td>
        <td><%= text_field_tag :number2 %> (required - no spaces or
dashes)
        </td>
    </tr>

<%= hidden_field_tag :employee_id, @phone.employee_id %>
    <tr >
        <td class="button form-right" align="right">
                <%= link_to "Cancel", "/dashboard.html" %>
        </td>
        <td class="button form-left"><%= f.submit "Finish >>" %>
        </td>
    </tr>
</table>
<% 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


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to