Storing combo box data in the database

Hi,
      I am using a combo box in a form along with some other form
elements.... The code that i have written is:

       <p><label for="employee_Fname">Fname</label><br/>
<%= text_field 'employee', 'Fname' %></p>

<p><label for="employee_Lname">Lname</label><br/>
<%= text_field 'employee', 'Lname' %></p>

<p><label for="employee_DOJ">Doj</label><br/>
<%= date_select 'employee', 'DOJ' %></p>

<p><label for="employee_email@Id">Email@id</label><br/>
<%= text_field 'employee', 'email@Id' %></p>

<p><label for="employee_service">Service</label><br/>
<%= select_tag 'employee', options_for_select(%w{None ITS RDS
Corporate},"None") %></p>

     The problem is when i submit the form data it is not storing
anything in the database.. But when i am not using combo box its
working fine. The controller code is...

    def create
    @employee = Employee.new(params[:employee])
    if @employee.save
      flash[:notice] = 'Employee was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

Can anybody help???
Thanks in advance…

<p><label for="employee_service">Service</label><br/>
<%= select_tag 'employee', options_for_select(%w{None ITS RDS
Corporate},"None") %></p>

    The problem is when i submit the form data it is not storing
anything in the database.. But when i am not using combo box its
working fine. The controller code is...

You're using select instead of select_tag, so there parameter is being
submitted as params[:employee], clobbering the rest of the data (a
hash in params[:employee]).
Either use select or your select_tag should be select_tag
'employee[foo]', ... instead of what it currently is.

Fred

Hi Fred,
             Thanks for your suggestion.... I have made the necessary
changes that you said....now the error is gone but still the data is
not getting added in the database...

First I tried with select at first:

<p><label for="employee_service">Service</label><br/>
<%= select( "employee", "service", { "None" => "None", "ITS" => "ITS",
"RDS" => "RDS", "Corporate" => "Corporate"}) %>

Next with select_tag:

<p><label for="employee_service">Service</label><br/>

<%= select_tag "employee[service]" , options_for_select(%w { None RDS
ITS Corporate} , "None") %>

Looking forward to your response....

Hi Fred,
            Thanks for your suggestion.... I have made the necessary
changes that you said....now the error is gone but still the data is
not getting added in the database...

The logical question to ask is why is it not getting saved? If a
validation is failing, which one? In the logs what is the data that
rails is receiving ? etc...

Fred

Hi Fred,
             I checked in the log file, you are right some validation
is failing… Actually when the create method is getting fired, rails
is generating an insert statement…in that insert statement the
field for which I have put the combo box that name isnt there.
             When I started developing this application I used
scaffold…the view part generated by rails did not have any combo
box. All were text fields except the date. I replaced one text field
with the combo box. Do you think that could be the problem??? I am
new to this ROR and I am not getting any clue…

Hi,
I forgot to give one information…The table in the database is having
5 fields…
   Fname, Lname, Date of joining, email and service. It is the last
field for which i am using the combo box. Is it possible to force
rails to generate a combo box according to the requirement???

            When I started developing this application I used
scaffold…the view part generated by rails did not have any combo
box. All were text fields except the date. I replaced one text field
with the combo box. Do you think that could be the problem??? I am
new to this ROR and I am not getting any clue…

In the log file, what is being submitted by the browser?

Fred

Hi Fred,
            I checked in the log file, you are right some validation
is failing.... Actually when the create method is getting fired,
rails
is generating an insert statement.....in that insert statement the
field for which I have put the combo box that name isnt there.
This is the log file statement:

Processing EmployeesController#create (for 127.0.0.1 at 2007-10-19
17:55:21) [POST]
Session ID: 8aecbc2b2dd0e9ad76116ce8eed371d8
Parameters: {"commit"=>"Create", "employee"=>{"DOJ(1i)"=>"2007",
"Lname"=>"fsfdsf", "DOJ(2i)"=>"10", "email@Id"=>"dfsfs",
"DOJ(3i)"=>"19", "Fname"=>"fsfs"}, "action"=>"create",
"controller"=>"employees"}

Your form isn't submitting the service field, so it's nothing to do with the database stuff.
You probably want to look at the source for your entire field to figure out why this is happening.

Fred.

Processing EmployeesController#create (for 127.0.0.1 at 2007-10-19
17:55:21) [POST]
  Session ID: 8aecbc2b2dd0e9ad76116ce8eed371d8
  Parameters: {"commit"=>"Create", "employee"=>{"DOJ(1i)"=>"2007",
"Lname"=>"fsfdsf", "DOJ(2i)"=>"10", "email@Id"=>"dfsfs",
"DOJ(3i)"=>"19", "Fname"=>"fsfs"}, "action"=>"create",
"controller"=>"employees"}
  e[4;36;1mEmployee Columns (0.000000)e[0m e[0;1mSHOW FIELDS FROM
employeese[0m
  e[4;35;1mSQL (0.000000)e[0m e[0mBEGINe[0m
  e[4;36;1mSQL (0.000000)e[0m e[0;1mINSERT INTO employees (`Lname`,
`email@Id`, `DOJ`, `Fname`) VALUES('fsfdsf', 'dfsfs', '2007-10-19',
'fsfs')e[0m
  e[4;35;1mSQL (0.000000)e[0m e[0mCOMMITe[0m
Redirected to http://localhost:3000/employees/list
Completed in 0.11000 (9 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/employees/create]