我有两个型号,用户和促销.这个想法是,促销活动可以拥有许多用户,用户可以有很多促销活动.
class User < ActiveRecord::Base has_and_belongs_to_many :promotions end class Promotion < ActiveRecord::Base has_and_belongs_to_many :users end
我也有一个promotion_users表/模型,没有自己的id.它引用了user_id和promotions_id
class PromotionsUsers < ActiveRecord::Base end
user = User.find(params[:id]) promotion = Promotion.find(params[:promo_id]) promo = user.promotions.new(promo)
这将导致以下错误:
NoMethodError: undefined method `stringify_keys!' for #<Promotion:0x10514d420>
如果我尝试这一行:
promo = user.promotions.new(promo.id)
我得到这个错误:
TypeError: can't dup Fixnum