class User < ActiveRecord::Base
has_one :wishlist
end
class Wishlist < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :items
end
And of course:
./script/rails generate migration create_item_wishlists wishlist_id:integer item_id:integer
.
: " " :
, , ( Item Product ), HABTM "" "items", :
@user.wishlist.items << item
@user.wishlist.save
:
class User
def add_to_wishlist(item)
wishlist.items << item
end
end
"", Ruby , , .