开发者

Rails Relationship Question

I have a HABTM relation ship be开发者_如何学Pythontween users and channels, where the user is subscribed to the channel. I want to show an "unsubscribe link" if the user is already subscribe to the channel. How do I test if the user is part of channel.users?


try calling:

channel.users.include? user

for the user you want to test. See the Ruby documentation on Arrays for more info. Good luck!


There's probably a few different ways to do this, but here's a simple one:

@user.channels.include? @channel 

=> true/false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜