validation polymorphic association
i have a polymorphic address model which i use in several forms. i do simple validation in that model but it doesn't work. what am i doing wrong?
Address Model
class Address < ActiveRecord::Base
attr_accessible :street1, :street2, :city, state, :zip
belongs_to :addressable, :polymorphic => true
validates_length_of :state, :maximu开发者_StackOverflow中文版n => 2, :too_long => "Field State is to long"
validates_numericality_of :zip, :on => :create, :message => "Zip Code must be numeric!"
validates_length_of :zip, :within => 5..9, :too_long => "Zip Code to long.", :too_short => "Zip Code to short"
end
Location Model
class Location < ActiveRecord::Base
has_one :address, :as => :addressable, :dependent => :destroy
belongs_to :account
accepts_nested_attributes_for :address
validates_presence_of :name
validates_length_of :name, :maximum =>80
end
Location Edit Form - for example
<% form_for [@account, @location] do |f| %>
<table>
<%= render :partial => 'form', :locals => {:f => f} %>
</table>
<%= f.submit("Update") %>
<% end %>
thanks for any help. Ed
What's the error? What validation isn't running? Also, you could take a look at: http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_associated
精彩评论