shengshou8 2008-1-2 10:15
expected, got HashWithIndifferentAccess
我在添加一个Question与多个Answers的时候吧Answers加入@Question是总是抱这个错
Answer expected, got HashWithIndifferentAccess
请高手帮帮啦!
xavier 2008-1-2 16:30
请把问题描述的再详细些
比如你的Question与Answers都是什么,是什么类
你在使用什么类库开发,或者什么框架?
yudi 2008-1-2 18:15
[font=Arial][color=DarkRed]
你的 Question 与 Answer 应该是 has_many 与 has_one 的关系。将 :answer 加入 @Question 的时候你需要建立一个实际的 :answer 对象。
如果 answer 属于 question (belongs_to)在你的 answer 里应该存有 Question_id, 类型是 Integer。建立 :answer 的时候需要确定 question_id (指明你在回答哪个问题)
所以类似的:
[code]
answer = Answer.new(prarams[:id])
answer.Question.id = @question.id ##注意命名, Question 是类,@question 是对象 (object)
answer.save
[/code]
这里是我对你问题的假设,最好在后面的问题里附上源代码。
[/color][/font]
[[i] 本帖最后由 yudi 于 2008-1-2 18:16 编辑 [/i]]