0

我有一个通过Cocoon gem使用嵌套字段的 rails 应用程序:

_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

我需要做的是在用户的编辑页面上检索每个任务描述值。

4

1 回答 1

1

不知道你所说的回声是什么意思,但要在_task_fields.html.hamldescription中获取任务,你可以这样做:

.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
于 2014-10-27T18:15:00.993 回答