1
我有兩個模型(問題和解答)稍微跟隨流行Railscasts:不需要(元?)中的Ruby/Rails數據
class Question < ActiveRecord::Base
has_many :answers
accepts_nested_attributes_for :answers, :allow_destroy => true
end
class Answer < ActiveRecord::Base
belongs_to :question
attr_accessible :content
end
的答案是建立(我的應用程序的目的)內編輯方法我question_controller.rb的:
2.times do
@question.answers.build
end
和編輯視圖中呈現 - edit.html.haml爲:
= f.fields_for :answers do |builder|
= render "answer_fields", :f => builder
當我想顯示答案時出現問題。裏面show.html.haml,我做的:
= for answer in @question.answers
= answer.content
答案內容顯示,但我也得到這個(不想要的)HTML代碼:
[#<Answer id: 11, question_id: 22, content: "100", created_at: "2012-04-02 08:34:50", updated_at: "2012-04-02 08:34:50">,]
如何刪除這個有什麼想法?我找不到這些額外數據的存在。
非常感謝提前!
是的,就是這樣。感謝你的回答! – mo5470 2012-04-02 10:23:44