私の製品にコントローラのuser_id、Location_id、product_dates_idを与えるにはどうすればいいですか?コントローラのクラスに、それが属するIDをどのようにクラスに与えますか?
class Product < ActiveRecord::Base
belongs_to :user
belongs_to :location
belongs_to :product_date
end
マイコントローラー:
def new
@location = Location.new
@product = Product.new
product_date = @location.product_dates.build
product_date.products.build
end
def create
@location = Location.new(params[:location])
end
マイ表:
create_table :products do |t|
t.integer :user_id
t.integer :location_id
t.integer :product_date_id
end
ありがとうございました。