조상
과정은 ancestry
당신이 달성하는 방법의 일련의 제공을 고려, 비교적 간단한 것 :
을 당신 '를 만드는 것입니다.
#app/assets/javascripts/application.js
$(document).on("change", "#your_select", function(){
var id = $(this).val();
$.ajax({
url: "/locations/" + id + "/siblings",
dataTye: "json",
success: function(data) {
// append result to your other select boxes
}
});
});
:
#config/routes.rb
resources :locations do
get :siblings
end
#app/controllers/locations_controller.rb
Class LocationsController < ApplicationController
repsond_to :json, only: :siblings
def siblings
@location = Location.find params[:id]
respond_with @location.children #-> might need some logic to differentiate between siblings/children
end
end
이 당신이 데이터의 응답을 관리 할 수 아약스 방법을 정의 할 수 있습니다 : 자바 스크립트에서 36,함수는 당신이 필요로하는 결과를 반환합니다 컨트롤러에 상대적 오브젝트를 통과하는
이것은 필요한 기능을 제공해야합니다.