Topic: Submitting an empty array as a param on POST action

I have a Task model, which is joined in a many-to-many relationship with an Objective model.

I have a Task edit form where a user can associate any Objective with a Task via checkboxes.

    <%= form_for @task do |f| %>
      <% Objective.all.each do |objective| %>
        <%= check_box_tag :objective_ids,, @task.objectives.include?(objective), :name => 'task[objective_ids][]' %>
      <% end %>
      <%= f.button :submit %>
    <% end %>

Updating a Task seems to work absolutely fine as long as one checkbox is checked by the user, but when  the user does not check any checkboxes, the :objective_ids param (which is an array of Objective ids) is not included in the POST action at all. Because of this, when I do @task.update_attributes(params[:task]) in the controller, the Task's collection of Objectives is not updated.

So how can I ensure the :objective_ids param is included in the POST, even if only as an empty array?

Last edited by FREAKMAN (2012-08-23 01:25:38)