0

尊敬的脂肪酶...軌道下拉菜單沒有關聯db表....

我有這些模型:

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-revisedhttp://railscasts.com/episodes/193-tableless-model嘗試了一切STIL l至無濟於事......

====================================

使用

IM簡單的表格......這讓我完成類似的任務,爲醫院創造形式...

<%= 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 %> 

(+附帶的CoffeeScript ...)

但在我目前的情況即時通訊不能夠做同樣的...因爲我沒有在sanctioned_posts模型中存儲師,區,區塊ID ......但我相信hospital_id在這種情況下會有所幫助......

日Thnx很多提前:) ...

問候

回答

0

爲什麼不使用的CoffeeScript和JQuery上做索引方法REST請求,並可以相應地配置您的路線? 例子:美國有學校,學校有學生

美國have_many學校,學校have_many學生

選擇伊利諾伊州。伊利諾伊州有11

get請求ID來/states/11/schools.json

SchoolsController < ApplicationController 
    responds_to :json 

    def index 
    states = State.find(params[:id}) 
    respond_with states.schools 
    end 
end