Ruby on rails Rails 3内容单元用于解决问题
我最近使用http://github.com/timriley/complex-form-examples构建了一个相当深的嵌套表单作为指导。表单部分在单击链接时使用以下命令呈现新字段:Ruby on rails Rails 3内容单元用于解决问题,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我最近使用http://github.com/timriley/complex-form-examples构建了一个相当深的嵌套表单作为指导。表单部分在单击链接时使用以下命令呈现新字段: <%= yield :warehouses_fields_template %> <%= yield :ratgrades_fields_template %> 在Rails2.3.8上,一切似乎都运行得很好,但是今天升级到Rails3RC之后,模板就不再加载了。是否发生了会使上述代码
<%= yield :warehouses_fields_template %>
<%= yield :ratgrades_fields_template %>
在Rails2.3.8上,一切似乎都运行得很好,但是今天升级到Rails3RC之后,模板就不再加载了。是否发生了会使上述代码无效的更改?还有人注意到同样的问题吗
任何帮助都将不胜感激,
谢谢
作为参考,这也是相关的jQuery代码:
$(function() {
$('form a.add_child').live('click', function() {
// Setup
var assoc = $(this).attr('data-association'); // Name of child
var content = $('#' + assoc + '_fields_template').html(); // Fields template
// Make the context correct by replacing new_<parents> with the generated ID
// of each of the parent objects
var context = ($(this).parents('.fields').children('input:first').attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
// context will be something like this for a brand new form:
// project[tasks_attributes][1255929127459][assignments_attributes][1255929128105]
// or for an edit form:
// project[tasks_attributes][0][assignments_attributes][1]
if(context) {
var parent_names = context.match(/[a-z]+_attributes/g) || []
var parent_ids = context.match(/[0-9]+/g)
for(i = 0; i < parent_names.length; i++) {
if(parent_ids[i]) {
content = content.replace(
new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
'$1[' + parent_ids[i] + ']'
)
}
}
}
// Make a unique ID for the new child
var regexp = new RegExp('new_' + assoc, 'g');
var new_id = new Date().getTime();
content = content.replace(regexp, new_id)
$(this).parent().before(content);
return false;
});
});
如果有帮助的话,我已经在一些相关页面中加入了一个要点:遇到了同样的问题。在rails 3中,现在必须使用符号。因此,请使用:
content_for :"#{association}_fields_template" do
及
删除给定的无用内容?方法,该方法现在是?的内置内容
也使用
<%= content_for :warehouses_fields_template %>
<%= content_for :ratgrades_fields_template %>
而不是
<%= yield :warehouses_fields_template %>
<%= yield :ratgrades_fields_template %>
遇到了同样的问题。在rails 3中,现在必须使用符号。因此,请使用:
content_for :"#{association}_fields_template" do
及
删除给定的无用内容?方法,该方法现在是?的内置内容
也使用
<%= content_for :warehouses_fields_template %>
<%= content_for :ratgrades_fields_template %>
而不是
<%= yield :warehouses_fields_template %>
<%= yield :ratgrades_fields_template %>
请编辑您的问题并格式化代码以使其可读。请编辑您的问题并格式化代码以使其可读。谢谢!解决了我遇到的问题。谢谢非常感谢。解决了我遇到的问题。谢谢