:별칭을 accepts_nested_attributes_입니까? <code>Topic</code> 모델에서
class Topic < ActiveRecord::Base
has_many :choices, :dependent => :destroy
accepts_nested_attributes_for :choices
attr_accessible :title, :choices
end
게시물 동안 작성, 제출 params
대신 :choices_attributes
의, 레일 예상 :choices
이며, 오류 제공 :
ActiveRecord::AssociationTypeMismatch (Choice(#70365943501680) expected,
got ActiveSupport::HashWithIndifferentAccess(#70365951899600)):
것은 거기는 accepts_nested_attributes_for
을 config (설정) 할 수있는 방법이다 JSON 호출에서 choices_attributes
대신에 choices
으로 전달되는 매개 변수를 허용 하시겠습니까?
def create
choices = params[:topic].delete(:choices)
@topic = Topic.new(params[:topic])
if choices
choices.each do |choice|
@topic.choices.build(choice)
end
end
if @topic.save
render json: @topic, status: :created, location: @topic
else
render json: @topic.errors, status: :unprocessable_entity
end
end