我有一个多态地址模型,我用几种形式。我在该模型中进行简单验证,但它不起作用。我做错了什么?
地址模型
class Address < ActiveRecord::Base
attr_accessible :street1, :street2, :city, state, :zip
belongs_to :addressable, :polymorphic => true
validates_length_of :state, :maximun => 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
位置编辑表单 - 例如
<% form_for [@account, @location] do |f| %>
<table>
<%= render :partial => 'form', :locals => {:f => f} %>
</table>
<%= f.submit("Update") %>
<% end %>
感谢您的帮助。 编
答案 0 :(得分:0)