Hello all,
Having a bit of a problem with validates_associated. I assume I’m
missing something out but basically got these two models -
class Seller < User
has_one :profile, :foreign_key => ‘user_id’, :dependent => :destroy
has_many :properties
validates_associated :profile
end
class Profile < ActiveRecord::Base
belongs_to :user
validates_presence_of :title, :forename, :surname, :address_a
end
My form looks like
Register as seller
<%= error_messages_for :user %>
<% form_for :user do |f| -%>
Login
<%= f.text_field :login %>
Email
<%= f.text_field :email %>
Password
<%= f.password_field :password %>
Confirm Password
<%= f.password_field :password_confirmation %>
<% fields_for :profile do |p| %>
Title
Mrs
Mr
Miss
Ms
Dr
Forename
<%= p.text_field :forename %>
Surname
<%= p.text_field :surname %>
Address
<%= p.text_field :address_a %>
Address
<%= p.text_field :address_b %>
Town/City
<%= p.text_field :town %>
County
<%= county_options_for_select %>
Postcode
<%= p.text_field :postcode %>
Subscribe to mailing list
<%= p.check_box :mailing_list %>
<% end %>
<%= submit_tag 'Sign up' %>
<% end -%>Basically when I submit the form with the missing fields required by
the Profile model, the form submits anyway.
Any suggestions?
Thanks in advance,
Alastair
Alastair M.
Standards compliant web development with Ruby On Rails, PHP and ASP
www.kozmo.co.uk
07738 399038