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_for @assignment do |f|%>
  <% Activity.all.each do |a|%>
    <% check_box_tag "assignment[activity_ids][]",,
@assignment.activity_ids.include?(> | <%>

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

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


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

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.