Tag: nested form for

未定义的方法`simple_nested_form_for’

为什么我在尝试使用nested_form Rails插件时遇到此错误?

Rails 4不更新嵌套属性

问题:当我点击相关features_controller.rb的#update操作时,它们是在现有嵌套属性的基础上创建的 ,而不是更新嵌套属性。 可能的原因:我认为问题在于我在Rails的form_for缺乏理解。 我认为故障在我的视图中,我如何呈现持久的嵌套属性,和/或我如何指定嵌套属性的id失败,导致它只是创建一个新的id feature.rb class Feature < ActiveRecord::Base … has_many :scenarios accepts_nested_attributes_for :scenarios, allow_destroy: true, reject_if: :all_blank … end features_controller.rb def update … project = Project.find(params[:project_id]) @feature = Feature.find(params[:id]) if @feature.update_attributes(feature_params) # checking feature_params looks good… # feature_params[‘scenarios’] => { } redirect_to project else render :edit end end … private def feature_params params.require(:feature).permit(:title, :narrative, […]

Rails 4:fields_for中的fields_for

我正在学习RoR,我正在尝试找到如何使用has_one模型在另一个中设置fields_for: class Child < ActiveRecord::Base belongs_to :father accepts_nested_attributes_for :father end class Father < ActiveRecord::Base has_one :child belongs_to :grandfather accepts_nested_attributes_for :grandfather end class Grandfather < ActiveRecord::Base has_one :father end 我在Railscasts上使用嵌套模型表单第1部分来获取这些:在children_controller.rb中: def new @child = Child.new father=@child.build_father father.build_grandfather end def child_params params.require(:child).permit(:name, father_attributes:[:name], grandfather_attributes:[:name]) end 我的表格: mother: grand mother: 我试图用以下方法检索数据: 但爷爷的名字不会起作用。 我找不到错误……有人帮忙吗? 谢谢!