ruby-on-rails - Rails动态添加嵌套表单错误未显示在参数中
问题描述
仅首先出现在参数中,但其他我们动态添加的不显示在参数中
应用js
(function () {
var ready;
ready = function () {
$(document).on('click', '.remove_fields', function (event) {
$(this).prev('input[type=hidden]').val('1');
$(this).closest('fieldset').hide();
return event.preventDefault();
});
$(document).on('click', '.add_fields', function (event) {
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$(this).before($(this).data('fields').replace(regexp, time));
$(document).find('.date-of-service').datepicker({
dateFormat: 'yy-mm-dd'
});
return event.preventDefault();
});
};
$(document).ready(ready);
$(document).on('page:load', ready);
}).call(this);
应用程序助手.rb
def link_to_add_fields(name, f, association, **args)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |ff|
render(association.to_s.singularize + "_fields", f: ff)
end
link_to(name, '#', class: "add_fields" , data: {id: id, fields: fields.gsub("\n", "")})
end
我们的表格
<%= f.fields_for :lineitems do |ff| %>
<%= render 'lineitem_fields', f: ff %>
添加另一个发票行项目'.html_safe, f, :lineitems%>
我们添加动态的部分
<%= f.fields_for :items do |ff| %>
<%= render 'items_fields', f: ff %>
添加另一个项目 item'.html_safe, f, :items%>
解决方案
推荐阅读
- php - 当我将值返回到我的视图页面时,应该会出现错误。$student 被定义为变量。我拉拉维尔
- javascript - 如何在光滑滑块的左侧对齐?
- javascript - 在 JavaScript 中以模数显示数字系列
- javascript - 如何使用数组 javascript 对时间范围进行分组?
- maven - 多模块项目中的 requiresDependencyResolution
- android - 如何从后台 Activity 更新前台 Activity 上的 RecyclerView?
- spring-boot - 将项目插入 thymeleaf 迭代
- arrays - 替代 ARRAYFORMULA 中的 INDIRECT 以引用上面的单元格
- jekyll - 在 https://example.com/blog/ 上出现 404 错误
- jquery - Colorbox - Ipad/Iphone 上的点击事件未触发