Everything in the header, I want to be able to delete an account that has not been verified after a specified period of time .
I use:
My User model has the following attributes:
devise :database_authenticatable, :confirmable, :registerable, :recoverable, :rememberable, :trackable, :validatable
And my db/schema.rb
create_table "users", :force => true do |t| t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" t.timestamp "reset_password_sent_at" t.timestamp "remember_created_at" t.integer "sign_in_count", :default => 0 t.timestamp "current_sign_in_at" t.timestamp "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.timestamp "created_at" t.timestamp "updated_at" t.string "confirmation_token" t.timestamp "confirmed_at" t.timestamp "confirmation_sent_at" end
A small bonus - in my User model, I indicate the relationship between my data, for example:
has_one :user_content, :dependent => :destroy
I want his children to be removed as well.
Thanks to everyone who can help!
Thanks jrdi , here is the answer for a database with SQLite 3
desc "Delete all unconfirmed users after 7 days" task :delete_unconfirmed_users => :environment do users = User.all(:conditions => 'confirmed_at is NULL AND confirmation_sent_at <= datetime(\'now\',\'-7 days\')') users.each do |user| user.destroy end end
For PostGRE (Heroku)
desc "Delete all unconfirmed users after 7 days" task :postgre_delete_unconfirmed_users => :environment do users = User.all(:conditions => 'confirmed_at is NULL AND confirmation_sent_at <= current_date - integer \'7\' ') users.each do |user| user.destroy end end
See his answer for details. Thanks @ a lot to him.