Nested attributes checkboxes multi-select

Witam,
mam problem z zapisem do bazy danych zagnieżdżonego formularza z opcją checkboxes multiselect, natomiast produkt mi się zapisuje do bazy danych tabeli Product, a wartości z zagnieżdżonego formularza chciałbym zapisać do tabeli Link , proszę o pomoc, poniżej mój kod:

class Product < ActiveRecord::Base
has_many :links
has_many :categories, :through=> :links
accepts_nested_attributes_for :links, allow_destroy: true
end

class Category < ActiveRecord::Base
has_many :links
has_many :products, :through=> :links
accepts_nested_attributes_for :links
end

class Link < ActiveRecord::Base
belongs_to :product , :inverse_of => :links
belongs_to :category, :inverse_of => :links
end

views/new
<%= form_for (@product), url: {action: “create”} do |f| %>
<%= f.text_field :name %>

<%= f.text_area :description %>

<%= f.text_field :price %>

<% Category.all.each do |category|%>
<%= check_box_tag “f[category_ids][]”, category.id, f.object.categories.include?(category.id) %>
<%= category.name %>
<% end %>
<%= f.submit :submit %>

<%end%>

controller:
def create
@product = Product.new(product_params)
@product.save
redirect_to action: ‘index’
end

def product_params
params.require(:product).permit(:name, :description, :price, :links_ids=>[])

end

Na wyjściu dostaje coś takiego:

Started POST “/warehouses” for 127.0.0.1 at 2016-05-13 05:48:52 +0200
Processing by WarehousesController#create as HTML
Parameters: {“utf8”=>“✓”, “authenticity_token”=>“9TVVSfe4R5zwepuYXcN2juHu17Z4Btfg9+soEfFp/C/kpsXRahnZSvrhTWv2BQ6MwseBpncKdpfOJbuz3o/Ovw==”, “product”=>{“name”=>“nowy produkt”, “description”=>“opis”, “price”=>“10”}, “f”=>{“category_ids”=>[“1”, “2”]}, “commit”=>“submit”}
(0.2ms) begin transaction
SQL (3.8ms) INSERT INTO “products” (“name”, “description”, “price”, “created_at”, “updated_at”) VALUES (?, ?, ?, ?, ?) [[“name”, “nowy produkt”], [“description”, “opis”], [“price”, 10.0], [“created_at”, “2016-05-13 03:48:52.318999”], [“updated_at”, “2016-05-13 03:48:52.318999”]]
(8.9ms) commit transaction

“PRINT PARAMS”
{“name”=>“nowy produkt”, “description”=>“opis”, “price”=>“10”}
Completed 302 Found in 41ms (ActiveRecord: 12.9ms)

Przede wszystkim nie zgadza Ci się klucz tam gdzie renderujesz listę kategorii. Poczytaj o fileds_for, sporo Ci to ułatwi.