summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2017-09-24 12:56:20 -0600
committermo <mo.khan@gmail.com>2017-09-24 12:56:20 -0600
commita67e0cb103f76df6095257857e5f980340f3c940 (patch)
tree7602d8e3f1c2bb721afaf4d891c1e3800c7166c6 /app
parent96d66bcdb7bad43c3ec08349d2d978aec307ec90 (diff)
upgrade to rails 5.1
Diffstat (limited to 'app')
-rw-r--r--app/models/photo.rb2
-rw-r--r--app/models/user_session.rb15
-rw-r--r--app/models/version.rb5
-rw-r--r--app/views/profiles/show.html.erb2
-rw-r--r--app/views/tutorial_tags/show.html.erb2
-rw-r--r--app/views/tutorials/index.html.erb2
-rw-r--r--app/views/tutorials/show.html.erb2
7 files changed, 21 insertions, 9 deletions
diff --git a/app/models/photo.rb b/app/models/photo.rb
index 2c9127e4..a3f3e547 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -1,5 +1,5 @@
class Photo < ApplicationRecord
- belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true
+ belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true, optional: true
scope :processed, ->{ where(image_processing: nil) }
def url_for(version_key, asset_host = ENV['ASSET_HOST'])
diff --git a/app/models/user_session.rb b/app/models/user_session.rb
index 3456c7d0..9dae0857 100644
--- a/app/models/user_session.rb
+++ b/app/models/user_session.rb
@@ -4,15 +4,20 @@ class UserSession < ApplicationRecord
has_one :location, as: :locatable
before_create :set_unique_key
attr_readonly :key
- scope :active, -> { where("accessed_at >= ?", 2.weeks.ago).where(revoked_at: nil).includes(:user) }
+ scope :active, -> do
+ where("accessed_at >= ?", 20.minutes.ago)
+ .where("created_at >= ?", 1.day.ago)
+ .where(revoked_at: nil)
+ .includes(:user)
+ end
def revoke!
- self.revoked_at = Time.now
+ self.revoked_at = Time.current
save!
end
def access(request)
- self.accessed_at = Time.now
+ self.accessed_at = Time.current
self.ip = request.ip
self.user_agent = request.user_agent
self.location = Location.build_from_ip(request.ip)
@@ -28,6 +33,10 @@ class UserSession < ApplicationRecord
return nil if key.blank?
self.active.find_by(key: key)
end
+
+ def sweep(time = 1.day)
+ delete_all("accessed_at < ?", time.ago)
+ end
end
private
diff --git a/app/models/version.rb b/app/models/version.rb
index 43ab3ef0..f15676a4 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -19,7 +19,10 @@ class Version
if photo.is_processed?
"#{asset_host}/#{blob_key}"
else
- ActionController::Base.helpers.asset_path("#{key}_default.png")
+ ActionController::Base.helpers.asset_path(
+ "#{key}_default.png",
+ skip_pipeline: true
+ )
end
end
diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb
index c81a33cb..328ebe6b 100644
--- a/app/views/profiles/show.html.erb
+++ b/app/views/profiles/show.html.erb
@@ -5,7 +5,7 @@
<%= avatar_for(@user, clazz: 'img-thumbnail') %>
</div>
<div class="col-9">
- <h1><%= @user.name %> <small>A member since <%= @user.created_at.to_s :foomat %>, with <%= @user.creations.length %> creations.</small> </h1>
+ <h1><%= @user.name %> <small>A member since <%= local_time(@user.created_at) %>, with <%= @user.creations.length %> creations.</small> </h1>
<h5><%= @user.city %></h5>
<hr>
<% if @user.website.present? %>
diff --git a/app/views/tutorial_tags/show.html.erb b/app/views/tutorial_tags/show.html.erb
index 3420b184..0f6dfea2 100644
--- a/app/views/tutorial_tags/show.html.erb
+++ b/app/views/tutorial_tags/show.html.erb
@@ -6,7 +6,7 @@
<% @tutorials.each do |tutorial| %>
<tr>
<td>
- <h4><%= link_to tutorial.heading, tutorial.url %> <small><%= tutorial.created_at.to_s :foomat %></small></h4>
+ <h4><%= link_to tutorial.heading, tutorial.url %> <small><%= local_time(tutorial.created_at) %></small></h4>
<% tutorial.tags.each do |tag| -%>
<%= link_to tutorial_tag_path(tag.name) do %>
<span class="badge badge-light"><%= tag.name %></span>
diff --git a/app/views/tutorials/index.html.erb b/app/views/tutorials/index.html.erb
index e31f8cea..978b20fe 100644
--- a/app/views/tutorials/index.html.erb
+++ b/app/views/tutorials/index.html.erb
@@ -6,7 +6,7 @@
<% @tutorials.each do |tutorial| %>
<tr>
<td>
- <h4><%= link_to tutorial.heading, tutorial.url %> <small><%= tutorial.created_at.to_s :foomat %></small></h4>
+ <h4><%= link_to tutorial.heading, tutorial.url %> <small><%= local_time(tutorial.created_at) %></small></h4>
<% tutorial.tags.each do |tag| -%>
<%= link_to tag.name, tutorial_tag_path(tag.name), class: 'badge badge-secondary' %>
<% end -%>
diff --git a/app/views/tutorials/show.html.erb b/app/views/tutorials/show.html.erb
index c4ae624f..e5efad66 100644
--- a/app/views/tutorials/show.html.erb
+++ b/app/views/tutorials/show.html.erb
@@ -6,7 +6,7 @@
</div>
<div class="col">
<h3><%= @tutorial.heading %></h3>
- <small><%= @tutorial.created_at.to_s :foomat %></small>
+ <small><%= local_time(@tutorial.created_at) %></small>
<p>
<% @tutorial.tags.each do |tag| -%>
<%= link_to tutorial_tag_path(tag.name) do %>