railscasts tokenfield @ 258 비디오를 수정하고 있습니다. 레일을 사용하는 것 같아요. 3Tokenfields - <book id : nil, name : nil, created_at : nil, updated_at : nil>에 대한 'author_tokens'정의되지 않은 메소드
설정 중에 많은 것을 연관 지어 설정하고 저자 ID를 ','로 나눠서 붙이면 난 고생했습니다. 레일 4.2.8 버전을 사용하고 있습니다.
오류 :
NoMethodError in Books#new
Showing /home/nicholas/labs/tokenfield-258/app/views/books/_form.html.erb where line #21 raised:
undefined method `author_tokens' for #
_form.html.erb
<div class="field">
<%= f.label :author_tokens, "Authors" %><br />
<%= f.text_field :author_tokens, data: {load: @book.authors} %>
</div>
books_controller.rb
def book_params
params.require(:book).permit(:name,:author_tokens)
end
book.rb
class Book < ActiveRecord::Base
has_many :bookauthors
has_many :authors, through: :bookauthors
def author_tokens=(ids)
self.author_ids = ids.split(',')
end
end
# created_at에 대해 정의되지 않은 메소드 'author_tokens'로 오류 메시지가 표시됩니다. nil, updated_at : nil>
이 문제를 해결할 수있는 사람이 있습니까? 레일 4.2.8 버전을 사용하고 있습니다.
attr_reader : book.rb의 author_tokens를 추가하면 문제가 해결됩니다. – nekolus