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
精彩评论