2014-10-27 112 views
0

我有經由Cocoon gem使用嵌套字段一個滑軌應用程序:抓鬥表單數據嵌套字段

_form.html.haml:

= form_for @project do |f| 
    %h3 Tasks 
    #tasks 
     = f.fields_for :tasks do |task| 
      = render 'task_fields', :f => task 
     .links 
      = link_to_add_association 'add task', f, :tasks 
    = f.submit 

_task_fields.html.haml:

.nested-fields 
    .field 
     = f.label :description 
     %br 
     = f.text_field :description 
     **********HERE's WHERE I WANT TO ECHO OUT THE DESCRIPTION FOR THIS PARTICULAR TASK** 
    .field 
     = f.check_box :done 
     = f.label :done 
    = link_to_remove_association "remove task", f 

我需要做的是在編輯頁面爲用戶檢索每個任務描述值。

+0

你是什麼意思*上檢索每個任務的描述值用戶的編輯頁面*?你不在這裏有任務嗎? '= f.text_field:description'? – Surya 2014-10-27 06:49:54

+0

@ User089247,我想再次回顯描述,而不是在標籤或文本字段中。我只想要領域的價值。 – Muhambi 2014-10-27 16:03:32

+0

回聲是什麼意思?你想要描述顯示在頁面上?或者它應該在日誌中默默顯示? – Surya 2014-10-27 18:13:01

回答

1

不知道你的迴音是什麼意思,但要獲得任務的description_task_fields.html.haml,你可以這樣做:

.nested-fields 
    .field 
     = f.label :description 
     %br 
     = f.text_field :description 
     = f.object.description # will show description if exists on form's object here. 
    .field 
     = f.check_box :done 
     = f.label :done 
    = link_to_remove_association "remove task", f