Randomize "featured" and "other by user" lists
This commit is contained in:
parent
2962fb8c5f
commit
9b80151511
@ -27,7 +27,7 @@ class HomeController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def featured_asciicasts
|
def featured_asciicasts
|
||||||
asciicast_repository.latest_featured_limited(3).decorate
|
asciicast_repository.random_featured_limited(3).decorate
|
||||||
end
|
end
|
||||||
|
|
||||||
def asciicast_repository
|
def asciicast_repository
|
||||||
|
@ -58,7 +58,7 @@ class AsciicastDecorator < ApplicationDecorator
|
|||||||
def other_by_user
|
def other_by_user
|
||||||
if user
|
if user
|
||||||
AsciicastDecorator.decorate_collection(
|
AsciicastDecorator.decorate_collection(
|
||||||
user.asciicasts.where('id <> ?', model.id).limit(3)
|
user.asciicasts.where('id <> ?', model.id).order('RANDOM()').limit(3)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
@ -19,9 +19,10 @@ class Asciicast < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :featured, -> { where(featured: true) }
|
scope :featured, -> { where(featured: true) }
|
||||||
scope :by_recency, -> { order("created_at DESC") }
|
scope :by_recency, -> { order("created_at DESC") }
|
||||||
|
scope :by_random, -> { order("RANDOM()") }
|
||||||
scope :latest_limited, -> (n) { by_recency.limit(n).includes(:user) }
|
scope :latest_limited, -> (n) { by_recency.limit(n).includes(:user) }
|
||||||
scope :latest_featured_limited, -> (n) {
|
scope :random_featured_limited, -> (n) {
|
||||||
featured.by_recency.limit(n).includes(:user)
|
featured.by_random.limit(n).includes(:user)
|
||||||
}
|
}
|
||||||
|
|
||||||
attr_accessible :title, :description, :time_compression
|
attr_accessible :title, :description, :time_compression
|
||||||
|
Loading…
Reference in New Issue
Block a user