我有一个div
. Tasks
每一个Task
都是单独的form
。
<div id="tasks">
<form id="task">...(@task.date = 2013-08-25)...</form>
<form id="task">...(@task.date = 2013-08-25)...</form>
<form id="task">...(@task.date = 2013-08-24)...</form>
<form id="task">...(@task.date = 2013-08-23)...</form>
<form id="task">...(@task.date = 2013-08-23)...</form>
<form id="task">...(@task.date = 2013-08-23)...</form>
<form id="task">...(@task.date = 2013-08-21)...</form>
<form id="task">...(@task.date = 2013-08-21)...</form>
</div>
我想单独包装Tasks
并添加标题信息。date
div
div
<div id="tasks">
<div class="day_tasks">
<div class="day_tasks_header">...</div>
<form id="task">...(@task.date = 2013-08-25)...</form>
<form id="task">...(@task.date = 2013-08-25)...</form>
</div>
<div class="day_tasks">
<div class="day_tasks_header">...</div>
<form id="task">...(@task.date = 2013-08-24)...</form>
</div>
<div class="day_tasks">
<div class="day_tasks_header">...</div>
<form id="task">...(@task.date = 2013-08-23)...</form>
<form id="task">...(@task.date = 2013-08-23)...</form>
<form id="task">...(@task.date = 2013-08-23)...</form>
</div>
<div class="day_tasks">
<div class="day_tasks_header">...</div>
<form id="task">...(@task.date = 2013-08-21)...</form>
<form id="task">...(@task.date = 2013-08-21)...</form>
</div>
</div>
可以使用 jQuery 在单独的 div 中添加一个date
到 div 的类名和.wrapAll
具有相同类的 div,然后.prepend()
在这个单独的 div 的顶部添加一个带有标题信息的 div。但是我不想把这么多的视图逻辑从 rails 端放到 JS 端。
Rails 可以做到吗?
我index.html.erb
的很简单:
<%= content_tag(:div, id: 'tasks') do %>
<%= render @tasks %>
<% end %>
_task.html.erb
也是一个简单的<%= form_for task ... %>