I am trying to save data to two tables - person and address. But first I want to do a lookup on the address table to make sure that the address entered does not already exist in the address table - if it does I want to extract the residence.id and plug that into the person table. Otherwise, I will just save the data to the respective tables. Here is the code I have tried thus far:
Code:
 def create # this part of the code does not work because I haven't a clue what I am doing
    @address_check = Residence.find(params[:residence])  #check for an existing address
    @person = Person.new(params[:person])
    if @address_check
	 @person.residence_id = @address_check.id
	 if @person.save
		 flash[:notice] = 'The Person was successfully created.'
		redirect_to :action => 'list'
	else
		render :action => 'new'
	end
    else  #this part of the code works
	@residence = Residence.new(params[:residence])
	if @person.save && @residence.save
		@person.update_attribute(:residence_id, @residence.id)
		flash[:notice] = 'The person was successfully created.'
		redirect_to :action => 'list'
	else
		render :action => 'new'
	end
    end
  end
The second part of the code works. The first part does not work primarily because I am not sure what I am doing. Is there some kind soul who can give me a hand with this.

Rick