Skip to content

Instantly share code, notes, and snippets.

@eri-b
Last active September 13, 2019 23:03
Show Gist options
  • Save eri-b/d26a02d79d35871c3eb4c57113245b16 to your computer and use it in GitHub Desktop.
Save eri-b/d26a02d79d35871c3eb4c57113245b16 to your computer and use it in GitHub Desktop.
class SitesController < ApplicationController
...
private
def find_site
@slug = params[:id].downcase
@site = Site.find_by(name: @slug)
if @site.present?
expired?
end
end
def expired?
last_post = @site.posts.last
if last_post.present?
activity_limit = 31
@days_til_expire = activity_limit - (Time.zone.now - last_post.updated_at)/(3600*24)
if @days_til_expire < 0
@site.destroy
redirect_to main_path(@site.name), notice: 'Previous site here was deleted due to inactivity.'
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment