尊敬的人...
我有这些模型:
class SanctionedPost < ActiveRecord::Base
attr_accessible :hospital_id, :sanctioned_posts, :designation_id
column :district_id
belongs_to:designation
belongs_to:hospital
belongs_to:district
belongs_to:division
end
class Hospital < ActiveRecord::Base
attr_accessible :beds, :fax_no, :hospital_name, :phone_no, :district_id, :institution_type_id, :location_id, :division_id, :block_id, :hospital_type_id, :IsAdministrativeLocation, :IsTribal, :latitude, :longitude
belongs_to:district
belongs_to:division
belongs_to:block
has_many:sanctioned_posts
end
class Division < ActiveRecord::Base
attr_accessible :division_name, :state_id
has_many:health_dept_locations
belongs_to:state
has_many:districts
has_many:hospitals
has_many:sanctioned_posts
validates_associated :districts
end
我希望能够在我的 sanctioned_posts 中创建下拉列表,以便部门缩小区域,缩小街区,缩小医院......(这样我就不必从一百万家医院中选择......).. .
我已经尝试了http://railscasts.com/episodes/88-dynamic-select-menus-revised和http://railscasts.com/episodes/193-tableless-model的所有内容,但仍然无济于事......
=====================================
我使用简单的表格...这使我能够为医院创建表格完成类似的任务...
<%= f.association :division,label_method: :division_name, value_method: :id, include_blank: false%>
<%= f.input :district_id do %>
<%= f.grouped_collection_select :district_id, Division.order(:division_name), :districts, :division_name, :id, :district_name, include_blank: true, label: 'District' %>
<% end %>
<%= f.input :block_id do %>
<%= f.grouped_collection_select :block_id, District.order(:district_name), :blocks, :district_name, :id, :block_name, include_blank: true, label: 'Block' %>
<% end %>
(+随附的咖啡脚本...)
但在我目前的情况下,我无法做同样的事情......因为我没有在 sanctioned_posts 模型中存储部门、地区、块 id ......但我相信 hospital_id 在这种情况下会有所帮助......
非常提前:) ...
问候