我有一个名为“Store”的模型,它有一个属性“City”,它有一个与之关联的“State”。我正在使用 simple_form 按州和/或城市创建商店过滤器。问题是,如何使 simple_form 不将“State”与“Store”相关联?
class State < ActiveRecord::Base
attr_accessible :name
has_many :cities
end
class City < ActiveRecord::Base
attr_accessible :name
belongs_to :state
has_many :stores
end
class Store < ActiveRecord::Base
attr_accessible :latitude, :longitude, :description, :city_id
validates :city, :presence => true
validates :description, :presence => true, :length => {:maximum => 500}
validates :latitude, :presence => true
validates :longitude, :presence => true
belongs_to :city
end
<%= simple_form_for @store, :html => { :class => 'add-store-form', :style => "display:none;" } do |f| %>
<table border="0">
<tr>
<td>Estado:</td>
<td>
<%= f.collection_select :state, State.all, :include_blank => false, :label => false,
:input_html => { :id => "state_id", :name => "state_id" } %>
</td>
</tr>
.
.
这种方式行不通。我怎样才能做到这一点?
提前致谢!