Hi folks,
I’m new to this… so hopefully someone can help me.
I have a few objects… Property and Address and Landlord… where a
Property has an address and a landlord has an address also.
I’ve modelled this in the db with the properties table having an
address_id and the landlord table having an address id.
My rb looks like:
class Property < ActiveRecord::Base
has_one :address
end
class Address < ActiveRecord::Base
end
the controller looks like:
def create
@property = Property.new(params[:property])
@property.address = Address.new(params[:address])
if @property.save
flash[:notice] = 'Property was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@property = Property.find(params[:id])
@address = @property.address
@landlords = Landlord.find_all
end
the form to save:
Details
<%= text_area 'property', 'description' %>
Price
<%= text_field 'property', 'price' %>
Rcpts
<%= text_field 'property', 'receptionCount' %>
Beds
<%= text_field 'property', 'bedroomCount' %>
Baths
<%= text_field 'property', 'bathroomCount' %>
Since
<%= datetime_select 'property', 'dateRegistered' %>
Number
<%= text_field 'address', 'number' %>
Street Name 1
<%= text_field 'address', 'streetName1' %>
but this is chucking out errors looking for a property_id column on the
database table address.
I dunno… I come from a java background and it ‘feels’ a bit backward
that it should be doing this.
I think i’m probably missing something simple… so if anyone could even
point me in the right direction that would be great!
Thanks in advance.
Marty H.