1

Iam을 사용하여 ancestry gem 위치 모델을 사용하십시오. 사용자가 부모를 선택하면 어떻게 자식을 표시합니까? 그러면 자식은 형제를 표시합니까?조상을 포함한 컬렉션 그룹을 추가하십시오.

어떻게 사용자 _form.html.erb에 적용 할 수 있습니까?

enter image description here

class Location < ActiveRecord::Base 
has_ancestry :cache_depth => true 
has_many :users 
end 

답변

0

조상

과정은 ancestry 당신이 달성하는 방법의 일련의 제공을 고려, 비교적 간단한 것 :

enter image description here

을 당신 '를 만드는 것입니다.

#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,함수는 당신이 필요로하는 결과를 반환합니다 컨트롤러에 상대적 오브젝트를 통과하는

이것은 필요한 기능을 제공해야합니다.

관련 문제