开发者

Active Record Store Delete

I'm having trouble deleting from active record store.

I want to delete based on the session data:

ActiveRecord::SessionStore::Session.find(:all).each do |s|
  if s.data[:userid] == 1234
    s.destroy
  end
end

does not seem to work, but:

ActiveRecord::SessionStore::Session.delete_all(["updated_at < ?", 12.hours.ago])

seems to work and:

ActiveRecord::SessionStore::Session.find(:all).each do |s|
  if s.data[:userid] == 1234
    ActiveRecord::SessionStore::Session.delete_all("session_id = ?", s.session_id)
  end
end

also doesnt work开发者_C百科.

I'm running version rails 2.3.2, ruby 1.8.7.


You can just pass Active Record's delete method the ID of the object you want to delete:

ActiveRecord::SessionStore::Session.delete(1234)

On another note, sure where the .data attribute is meant to be coming from in the above example. Session.find(:all) will return an array of Session objects which you then iterate through. Session does not have a userid column unless you are hacking the default Session store to add it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜