0

나는 조상 보석 & 위치 구조를 만들도록 설치했습니다.가계 보석과 has_many 연결 만들기

  • 알래스카
  • 캘리포니아
    • 로스 앤젤레스
    • 프레스노
    • Cincotta (프레스노)
    • 하몬드 (프레스노)
      • 멜빈 (프레스노)
        • 멜빈 1
        • 멜빈 2
        • 멜빈 3
  • 애리조나
  • 콜로라도

내 게시물과 위치 모델

class Location < ActiveRecord::Base 
include Tree 
has_many :posts 
end 

class Post < ActiveRecord::Base 
    belongs_to :location 
end 

새 게시물을 추가 할 때 드롭 다운으로 깊이 4 수준 (멜빈 1, 멜빈 2, 멜빈 3) 만 표시하는 방법.

Location.all.at_depth(4) 

select 입력 요소 렌더링하는 데 사용할 수 Thiscan :

답변

1

당신은 그래서 당신은 at_depth 사용할 수 있습니다 cache depth을 활성화해야

<%= select :location_id, Location.all.at_depth(4) { |l| [ l.name, l.id ] } %> 
+0

난 후 컨트롤러에 추가하고 무엇을 ... 내가 무엇을 # GET/posts/new를 추가하십시오. def new @post = Post.new end –

+0

고맙습니다. @zwippie. 나는 새로운 질문을 만든다. http://stackoverflow.com/questions/24801193/post-and-location-association-with-ancestry-gem –