Hi Ryan.
Thanks for taking an interest on this. I am only using 'save' on the
last page's action method in the controller (4 pages: name, address,
phones and save; page 'save' has a button to invoke 'new', which just
redirects to 'name'). There is no use of 'create' anywhere in the
model, the controller or the view. I created some validation methods
in the model because that's where they are supposed to be but seeing
what was happening I took them out and put the validations in the
controller to see if somehow the model was using functionality I
didn't know it might have that would post the data to the row whenever
a method is invoked (just trying to guess). The problem persists.
Below is the full controller's code and the model is now empty. The
table was created with a migration so in addition to the fields in the
validation methods there is the 'id' field in it. Thanks again for
helping:
class EmployeesController < ApplicationController
def name
get_employee
flash[:employee] = @employee
end
def address
validate 'name'
end
def phones
validate 'address'
end
def save
validate 'phones'
return if !@employee.errors.empty?
@employee.save
end
def new
flash[:employee] = Employee.new
redirect_to :action => :name
end
private
def validate( action_name )
get_employee
if @employee.errors.empty?
update_employee
if action_name == 'name'
#@employee.validate_name
validate_name
elsif action_name == 'address'
#@employee.validate_address
validate_address
elsif action_name == 'phones'
#@employee.validate_phones
validate_phones
end
redirect_to :action => action_name.to_sym if !
@employee.errors.empty?
end
flash[:employee] = @employee
end # def validate( method_name )
def get_employee
@employee = flash[:employee] ||= Employee.new
end
def update_employee
@employee.update_attributes(params[:employee])
end
def validate_name
@employee.errors.clear
@employee.errors.add(:first, 'Please enter first name.') unless !
@employee.first.nil? && @employee.first != ''
@employee.errors.add(:last, 'Please enter last name.') unless !
@employee.last.nil? && @employee.last != ''
@employee.errors.add(:identification, 'Please enter
identification.') unless !@employee.identification.nil? &&
@employee.identification != ''
end
def validate_address
@employee.errors.clear
@employee.errors.add(:street, 'Please enter street.') unless !
@employee.street.nil? && @employee.street != ''
@employee.errors.add(:city, 'Please enter city.') unless !
@employee.city.nil? && @employee.city != ''
@employee.errors.add(:state, 'Please enter state.') unless !
@employee.state.nil? && @employee.state != ''
@employee.errors.add(:zip, 'Please enter zip code.') unless !
@employee.zip.nil? && @employee.zip != ''
end
def validate_phones
@employee.errors.clear
@employee.errors.add(:phone, 'Please enter phone number.') unless !
@employee.phone.nil? && @employee.phone != ''
@employee.errors.add(:cell, 'Please enter cell number.') unless !
@employee.cell.nil? && @employee.cell != ''
end
end