0
나는이있다 : has_many : 다음, class_name을 : 다음 has_many : followed_books를 통해 : 다음, 소스 : 책내가 따라 다니는 책의 저자 이름을 어떻게 알 수 있습니까? user.rb (모델)에서
followed.rb에서, 나는 책 'ID를 가지고 및 사용자의 ID book.rb에는 작성자 (작성자 이름 포함)가 있습니다.
어떻게 나의 책을 쓸 수 있습니까?
current_user.followed_books (: 작성자) 또는 current_user.followed_books.author입니까?
current_user.followed_books.includes(:author).pluck("authors.name")
경우 :
current_user.followed_books.pluck(:author)
'는 저자가'객체 인 경우 '저자가'그냥 같은 이름을 액세스 할 수있는 저자의 이름을 나타내는 속성 인 경우
내가 쓸 수있는 ID를 원한다면 : current_user.followed_books.pluck (: author) .id? – Kevin77
'저자'가 개체 인 경우 내 대답을 편집했으며 db의 테이블을 '작성자'라고합니다 –
오! 당신은 매우 숙련 된 사람입니다! 작성자는 문자열입니다. 마지막 질문, 제발 :) 그리고 그 저자의 모든 책을 원한다면? current_user.followed_books.includes (: author) .pluck ("authors.book")? – Kevin77