是否有某种简写
@notifications = Notification.find(:all, :conditions => ['expires_at > ?', Time.now])
notif = Notification.find(:all, cookie[0].to_i)
@notifications.delete(notif[0]) if not notif.empty?
Run Code Online (Sandbox Code Playgroud)
cookie是存储在cookie中的通知的id.这是在迭代中,删除用户不想看到的通知.
谢谢!=)
如果这是一个activerecord对象数组,您可以像这样从数据库中删除.
Notification.delete_all(:id => cookie[0].to_i)
如果这只是一个数组,那么你可以使用delete if
@notifications.delete_if{|x| x == cookie[0].to_i}
| 归档时间: |
|
| 查看次数: |
7617 次 |
| 最近记录: |