Last active
September 13, 2019 23:03
-
-
Save eri-b/d26a02d79d35871c3eb4c57113245b16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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