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.haml で of タスクを取得するには、次descriptionのようにします。

.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 に答える