Ruby on rails 嵌套表单未知属性:问题\u id
我有两种型号:Ruby on rails 嵌套表单未知属性:问题\u id,ruby-on-rails,ruby-on-rails-4,nested-forms,Ruby On Rails,Ruby On Rails 4,Nested Forms,我有两种型号: class Question < ActiveRecord::Base has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers end class Answer < ActiveRecord::Base belongs_to :question end 您似乎忘记在答案表中创建问题id字段 您的两个模型之间存在1-M关系问答。确保答案表中有外
class Question < ActiveRecord::Base
has_many :answers, :dependent => :destroy
accepts_nested_attributes_for :answers
end
class Answer < ActiveRecord::Base
belongs_to :question
end
您似乎忘记在答案表中创建
问题id
字段
您的两个模型之间存在1-M关系
问答。确保答案表中有外键问题id
您似乎忘记在答案表中创建问题id字段。您的两个模型之间存在1-M关系。确保答案表中有外文关键问题。你完全正确,谢谢。我刚刚添加了答案。:)
class QuestionsController < ApplicationController
def new
@question = Question.new
4.times { @question.answers.build }
end
end
= simple_form_for @question do |f|
= f.input :title
= f.simple_fields_for :answers do |a|
= a.input :text
= f.submit