I am working on a Rails 4 app and trying to implement HABTM relationship between Category and Recipe. I am getting the above error. I followed a railscast that worked in the video but didn't work for me. I added strong parameters.
Schema:
create_table "categories", force: :cascade do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  create_table "categories_recipes", id: false, force: :cascade do |t|
    t.integer "category_id"
    t.integer "recipe_id"
  end
  create_table "recipes", force: :cascade do |t|
    t.string   "name"
    t.string   "source"
    t.string   "servings"
    t.string   "comment"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end
Models:
class Category < ActiveRecord::Base
  has_and_belongs_to_many :recipes
  validates :name, :presence => true
end
class Recipe < ActiveRecord::Base
  has_and_belongs_to_many :categories
  validates :name, :presence => true
  validates :source, :presence => true
  validates :servings, :presence => true
  validates :comment, :presence => true
end
Form:
<%= form_for @recipe do |f| %>
  <p>
    <%= f.label :name %>
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :source %>
    <%= f.text_field :source %>
  </p>
  <p>
    <%= f.label :servings %>
    <%= f.text_field :servings %>
  </p>
  <p>
    <%= f.label :comment %>
    <%= f.text_field :comment %>
  </p>
  <%= hidden_field_tag 'recipe[category_ids]', nil %>
  <% Category.all.each do |category| %>
    <p>
      <%= check_box_tag 'recipe[category_ids][]', category.id, @recipe.category_ids.include?(category.id) %>
      <%= category.name %>
    </p>
  <% end %>
  <%= f.submit %>
<% end %>
recipes_controller.rb:
def create
    @recipe = Recipe.new(recipe_params)
    if @recipe.save
      redirect_to recipes_path
    else
      render :new
    end
  end
  private
  def recipe_params
    params.require(:recipe).permit(:name, :source, :servings, :comment, {category_ids:[]})
  end
layout.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Friends</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
 
    