Associate HABTM Model on Create? Passing in a user_id?


Could anyone help me pass a user_id when creating a child record with a
HABTM relationship? I’m basically trying to create a record from the
following url


I tried several variants of the following, but keep getting various
errors. My first attempt below yeilds ‘invalid Users’ error and the
second yields a type mismatch error “user expected got string.”

<% form_for(@tasks) do |f| %>
#things I tried:
<%= hidden_field_tag “tasks[user_ids][]”, params[:user_id] %>
<%= f.hidden_field :user_ids, params[:user_id] %>
<%= f.submit ‘Create’ %>
<% end %>

I get why I’m getting these errors, but haven’t been able to figure out
the correct syntax to get it to pass through. perhaps I’ve been making
the wrong assumption that if I could pass the user_id to my
create_action, rails would understand that it needed to create the HABTM
between the new record and the user_id I’m referencing.

Any help would be appreciated.