刘华佼的全栈学习记录

如何实作加入或退出群组

| Comments

目标

实作加入或退出群组

步骤一:

app/models/user.rb中加入:

  def join!(group)
    participated_groups << group
  end

  def quit!(group)
    participated_groups.delete(group)
  end

步骤二:

开rails console
输入:

u = User.first
g = Group.first
u.join!(g)
u.is_member_of?(g)
u.quit!(g)
u.is_member_of?(g)
exit

测试join/quit函数定义是否功能正常

Comments

comments powered by Disqus