내 chapters_controller
의 강력한 매개 변수는 Book
엔터티와 Chapter
엔터티가있을 때 무엇이되어야합니까?레일 앰버 강력한 매개 변수 설명
참고 : JSON API를 사용하고 있습니다.
:title, :order, :content, :published, :book, :picture
을 아니면해야합니다 : 내 chapters_controller
에서
, 내 강력한 매개 변수가 있어야한다
:title, :order, :content, :published, :book_id, :picture
내 엠버 응용 프로그램에서 다음, 대신 :book_id
의 :book
를 사용하는 경우, 내가 갈 때 새 장을 만들려면이 장을 만들고 부모 장부에이 장을 연결할 수 있지만 내 테스트는 실패합니다.
def setup
@book = books(:one)
@new_chapter = {
title: "Cooked Wolf Dinner",
order: 4,
published: false,
content: "The bad wolf was very mad. He was determined to eat the little pig so he climbed down the chimney.",
book: @book
}
end
def format_jsonapi(params)
params = {
data: {
type: "books",
attributes: params
}
}
return params
end
...
test "chapter create - should create new chapter assigned to an existing book" do
assert_difference "Chapter.count", +1 do
post chapters_path, params: format_jsonapi(@new_chapter), headers: user_authenticated_header(@jim)
assert_response :created
json = JSON.parse(response.body)
attributes = json['data']['attributes']
assert_equal "Cooked Wolf Dinner", attributes['title']
assert_equal 4, attributes['order']
assert_equal false, attributes['published']
assert_equal @book.title, attributes['book']['title']
end
end
내 콘솔에 연결 유형 불일치 오류가 표시됩니다.
아마도 내 라인 :
book: @book
를 일으키는?
어느 쪽이든, 장의 느낌은 내게 chapters_controller
강력한 매개 변수에 :book
을 사용해야한다고 말하고 있습니다.
내 테스트가 통과하지 못하고 테스트 통과를 위해 매개 변수 해시를 작성하는 방법을 잘 모르겠습니다.