我正在使用 formtastic 和 formtastic_cocoon 创建一个嵌套表单。除了一个异常(exception),所有似乎都可以动态地向现有表单添加嵌套表单。我有用户,用户有条目。当我创建一个用户并添加一个条目时,我最终得到-用户 - 条目(空) - 入学测试 1我应该只有-用户 - 入学测试 1我不确定为什么总是出现空白条目。我的模型是类用户 验证 :name, :presence => true has_attached_file :照片 has_many :tasks, :dependent => :destroy accepts_nested_attributes_for :tasks, :allow_destroy => true结尾类任务 attr_accessible : 条目 归属地:用户结尾我的创建 Controller 是(我认为这是正确的 Controller ) 定义创建 @user = User.new(params[:user]) 如果@user.save flash[:notice] = "成功创建用户。" 重定向到@user 别的 渲染: Action => '新' 结尾 结尾 定义创建 @task = Task.new(params[:task]) 如果@task.save flash[:notice] = "任务创建成功。" 重定向到@task 别的 渲染: Action => '新' 结尾 结尾空条目显示在数据库中,所以我不认为这是 html.erb 文件的问题,但如果有帮助,我可以在此处发布它们。 最佳答案 事实证明,这可能是 formtastic_cocoon 处理表单的方式的问题。查看 html 源代码时,嵌套表单在页面中,但被隐藏。我将模型更改为accepts_nested_attributes_for :tasks, :reject_if=> proc {|attributes|属性[:entry].blank?}, :allow_destroy => true关于ruby-on-rails - 动态嵌套表单总是创建一个额外的空白条目 - 使用 formtastic_coocoon,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4941212/
10-11 09:09