开发者

Rails Relationship Question

开发者 https://www.devze.com 2023-01-30 03:55 出处:网络
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

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

精彩评论

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