has_many through , or habtm , using form

i think there ara two ways of relate products and categories , basically i want to fix one product(e.g hp dv7....) to some categories (notebook,17"notebooks...) i made a table named categorization(incuding category_id,product_id fields) then in models i write these codes below

class Product < ActiveRecord::Base         has_many :categories, :through => :categorizations         has_many :categorizations end

class Categorization < ActiveRecord::Base   belongs_to :product   belongs_to :kategori end

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

i'm not sure how rails complain which field will be use for relation products and categories in categorization table(this is missing chain i think)...anyway if we continue :slight_smile: , i have to make form (creating new product and add a new row in categorization table for identify categories of product we want to add at the same time )

which method should i use for add new product and its categories at the same time?

Many thanks , whats your suggestion about making a form using these codes?

lecielbleu wrote:

Many thanks , whats your suggestion about making a form using these codes?

You can certainly do that. Check out Stephen Chu's params[:fu] series of blog posts, as well as the Railscasts on complex forms and the documentation regarding nested resources in Rails 2.3.2.

Best,

Thanks Marnen i solved using Stephen Chu's params[:fu] fantastic series :slight_smile: