views:

30

answers:

1

Is there some sort of short hand for

@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?

cookie is an id of a notification stored into cookies. this is in an iteration, that removes notifications that the user doesn't want to see.

thanks! =)

A: 

If this is an array of activerecord objects, you could delete from the database like this.

Notification.delete_all(:id => cookie[0].to_i)

If this is just an array, then you can use the delete if

@notifications.delete_if{|x| x == cookie[0].to_i}

Geoff Lanotte
an array has no method, delete_all. =\
DerNalia
is this an array of activerecord objects? and if so, so you want to delete just from the array or delete from the database? I added a one-liner to delete from an array. Not totally sure what @notifications is now.
Geoff Lanotte
close, @notifications.delete_if{|x| x.id == cookie[0].to_i} did the trick. thanks for helping!
DerNalia