
Question:
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.
I'm running version rails 2.3.2, ruby 1.8.7.
Solution:1
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.
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon