나는 모델 "사물"을 가지고 있는데, 각각 has_many "Comments", 그리고 각각 has_many "Votes". Thing 쇼 페이지의 댓글에 투표하고 싶습니다. 이것이 내가 지금까지 가지고있는 것입니다.
댓글 컨트롤러 :
def votecomment
@comment = Comment.find(params[:id])
Vote.create!(voteable_id: params[:id], voteable_type: 'Comment')
redirect_to current_thing
end
사물보기 :
<%= link_to “Vote”, vote_comment_path(:id => comment.id), method: :post %>
노선 :
post 'comments/:id/vote' => 'comments#vote', as: 'vote_comment'
하지만이 오류가 다시 발생합니다.
NameError in CommentsController#votecomment
undefined local variable or method `current_thing' for #<CommentsController:0x007f98efa69c00>
방법을 Things 컨트롤러로 이동하려고 시도했지만 똑같은 유형의 오류가 발생했습니다.
내가 무엇을 잘못하고 있지?
comment.rb에 다음과 같은 관계가 있다고 가정합니다.
belongs_to :thing
를 사용하여 댓글의 사물 객체에 액세스 할 수 있습니다 @comment.thing
. redirect_to가 객체를 받아들이 기 때문에 다음과 같이 할 수 있습니다.
redirect_to @comment.thing
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다