2011-08-15 121 views
1

我試着遵循RailsCasts的例子來獲取動態表單的工作方式,但無法正常工作。基本上我有一個has_many任務的項目,我希望能夠在創建或編輯項目時動態添加和刪除任務。我怎樣才能做到這一點?Rails 3.1動態嵌套表格

+0

您能否要麼顯示您的c頌?我可以幫你一把! – LearningRoR

回答

1

Apneadiving是正確的,但它並沒有真正幫助新人。

這隻適用於rails 3.1和ruby 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