Nested forms using checkboxes

Hi everyone,

I want to build a form following this idea:

I have Assignment, Activity, Task, AssignmentActivity, ActivityTask and AssignmentActivityTask models 1 assignment has many activities and 1 activity has many tasks

(there's a many-to-many relation between: Assignment - Activity AssignmentActivity - Task, and a One-to-many relation: Activity - Task) I've made the Assignment-Activity form using this idea:

and the form looks like this

_form.html.erb

<% form_for @assignment do |f|%>   <% Activity.all.each do |a|%>     <% check_box_tag "assignment[activity_ids]", a.id, @assignment.activity_ids.include?(a.id)%> | <% a.name%>   <%end%> <%end%>

So it saves inside the assignment, all the activities that I've checked.

The problem comes when I tried to add the ability to save task inside this form. This is what I've tried

_form.html.erb

<% form_for @assignment do |f|%>   <% Activity.all.each do |a|%>     <%= check_box_tag "assignment[activity_ids]", a.id, @assignment.activity_ids.include?(a.id)%> | <%= a.name%> <br>     <% a.tasks.each do |t|%>       #THIS       <%= check_box_tag "assignment[activity_ids]", t.id, "Something here"%> | <%= t.task_name %><><br>     <%end%>   <%end%> <%end%>

But I'm not sure how to write the line after the comment.

So when it saves it should save inside the assignment the activities and also the tasks the I've checked

Is there a way of doing this?

Thanks in advance

Javier Q.