Rails rails 3 中一个 many to many 问题,求教

zealinux · September 09, 2012 · Last by fenprace replied at September 09, 2012 · 2139 hits

http://ihower.tw/rails3/activerecord-relationships.html

many-to-many,按照他写的教程,rails console 出现错误

g = Group.create( :name => 'ruby taiwan' ) e1 = Event.first e2 = Event.create( :name => 'ruby tuesday' ) EventGroupship.create( :event => e1, :group => g ) # => ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: event, group EventGroupship.create( :event => e2, :group => g )

如果,改成 EventGroupship.create( :event_id => e1.id, :group_id => g.id ), 则, g.events #=>[ ] 剩下的也都是空集。

g.events e1.groups e2.groups

这个问题怎么解决?

谢谢

EventGroupship 这样的命名法貌似已经取缔了,推荐 LZ 看下 http://railscasts-china.com/episodes/tags

You need to Sign in before reply, if you don't have an account, please Sign up first.