【发布时间】:2025-11-30 16:40:01
【问题描述】:
我尝试按照 RailsCasts 示例让动态表单工作,但无法正常工作。基本上我有一个包含多个任务的项目,我希望能够在创建或编辑项目时动态添加和删除任务。我该怎么做?
【问题讨论】:
-
你能给出你的代码吗?我可以帮你!
标签: jquery ruby-on-rails ajax ruby-on-rails-3.1
我尝试按照 RailsCasts 示例让动态表单工作,但无法正常工作。基本上我有一个包含多个任务的项目,我希望能够在创建或编辑项目时动态添加和删除任务。我该怎么做?
【问题讨论】:
标签: jquery ruby-on-rails ajax ruby-on-rails-3.1
直接使用 Ryan Bate 的 gem。
It lies here with documentation.顺便说一句,文档准确地描述了您的用例。
【讨论】:
Apneadiving 是正确的,但它并不能真正帮助新人。
这仅适用于 ruby on rails 3.1,可能适用于 3.2,但我还没有测试过。
如果您将以下内容添加到您的Application_root/app/assets/javascripts/application.js 文件中(我将其添加到最后一行):
//= require jquery_nested_form
一个新鲜的看起来如下
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require jquery_nested_form
或者如果你出于某种原因使用原型:
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require prototype_nested_form
【讨论】: