0
나는 레일에 대한 조상 보석을 얻으려고 노력했지만 가장 단순한 경우조차도 실패하는 것 같습니다. 나는 신참 선수이기 때문에 쉽게 신참 실수를 할 수 있습니다.Rails Ancestry Gem은 자식/부모에게 액세스 할 수 없습니다.
내가 구현하려고 시도했던 것은 조상의 하위/상위 기능을 사용하여 댓글에 대한 답장이 모두 동일한 페이지에 표시되는 정상적인 주석 달기 시스템에 불과했습니다. 다음은
내가 부모 자식 관계를 설정하려고하는 응답 링크가 내 공연의 HTML입니다 :<p id="notice"><%= notice %></p>
<%[email protected]?%>
<p>
<strong>Body:</strong>
<%= @comment.body %>
</p>
<p>
<%if [email protected]?%>
<% @children.each do |c|%>
c.body
<%end%>
<%end%>
</p>
<p>
<strong>Author:</strong>
<%= @comment.author %>
</p>
<%= link_to 'Reply', new_comment_path, :parent_id => @comment %>
<%= link_to 'Edit', edit_comment_path(@comment) %> |
<%= link_to 'Back', comments_path %>
을 그리고 여기 컨트롤러 방법 중 일부입니다 :
class CommentsController < ApplicationController
before_action :set_comment, only: [:show, :edit, :update, :destroy]
# GET /comments
# GET /comments.json
def index
@comments = Comment.all
end
# GET /comments/1
# GET /comments/1.json
def show
@[email protected]
end
# GET /comments/new
def new
@parent_id = params.delete(:parent_id)
@comment = Comment.new(:parent_id => @parent_id)
end
//omitted code
private
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end
을
나는 위의 코드와 부모/자식 관계를 얻지 못하는 것 같습니다.