Ajax Bad Request 400 Rails
<p>I'm getting bad request error 400 using Ajax on Rails.
When i submit my form I have a string to send as parameter from Jquery and i want to retrieve it from params[:assignee] so i can extract the string and save it through my controller.
My controller: </p>

<pre><code>    def create
    @task = Task.new(task_params)
    @task.user = current_user
    username = params.permit[:assignee]
    @task.assignee = username

    #set_category
    respond_to do |format|
      if @task.save
        format.html { redirect_to tasks_url, notice: 'Task was successfully created. '+task_params.inspect}

        #format.html { redirect_to @task, notice: 'Task was successfully created.' }
        format.json { render :show, status: :created, location: @task }
      else
        format.html { render :new }
        format.json { render json: @task.errors, status: :unprocessable_entity }
      end
    end
  end

def task_params
  params.require(:task).permit(:owner, :value, :completed, :category, :date, :assignee)

end
</code></pre>

<p>And this is my JS:</p>

<pre><code> $( "#new_task" ).submit(function() {
    alert("form: "+assignee);
  //event.preventDefault();
 $.ajax({
   url: "/tasks",
   type: "POST",
   data: {assignee},
   dataType: "json",
   success: function(data) {
       alert('successfully');
     },
    error: function(xhr, textStatus, error) {
     alert(xhr.statusText+""+textStatus+""+error);
  }
   });
});
</code></pre>

<p>assignee is an username selected in a jquery auto-complete form:</p>

<pre><code>select: function(event, ui) {
    var terms = split(this.value);
    // remove the current input
    terms.pop();
    // add the selected item
    terms.push(ui.item.value);
    // add placeholder to get the comma-and-space at the end
    terms.push("");
    this.value = terms.join("");
    assignee=this.value;
    $('input[name=commit]').prop("disabled",false);

    return false;
}
</code></pre>

<p>My root is "task/" where you can see saved tasks and a form to create a new one.
I searched a lot on the net and I tried them all. How can I do? Thanks so much</p>