diff --git a/admin/app/admin/promo_latest.rb b/admin/app/admin/promo_latest.rb index 3aae396c0..676aa8638 100644 --- a/admin/app/admin/promo_latest.rb +++ b/admin/app/admin/promo_latest.rb @@ -31,7 +31,6 @@ ActiveAdmin.register JamRuby::PromoLatest, :as => 'Latest' do def new @promo = JamRuby::PromoLatest.new @promo.aasm_state = 'active' - @latests = PromoLatest.latest_candidates super end @@ -42,7 +41,6 @@ ActiveAdmin.register JamRuby::PromoLatest, :as => 'Latest' do def edit @promo = resource - @latests = PromoLatest.latest_candidates super end diff --git a/ruby/lib/jam_ruby/models/promotional.rb b/ruby/lib/jam_ruby/models/promotional.rb index 660a768e6..407a30c1e 100644 --- a/ruby/lib/jam_ruby/models/promotional.rb +++ b/ruby/lib/jam_ruby/models/promotional.rb @@ -34,9 +34,11 @@ class JamRuby::Promotional < ActiveRecord::Base aasm_state end - def self.active(max_count=100) + def self.active(max_count=10) rel = self.where(:aasm_state => ACTIVE_STATE) - rel = rel.limit(mc) if 0 < (mc = max_count.to_i) + if 0 < (mc = max_count.to_i) + rel = rel.limit(mc) + end rel end @@ -82,31 +84,11 @@ class JamRuby::PromoLatest < JamRuby::Promotional attr_accessible :latest def music_session_history - @music_session_history ||= MusicSessionHistory.find_by_id(latest_id) + self.latest if self.latest.is_a? MusicSessionHistory end def recording - @recording ||= Recording.find_by_id(latest_id) - end - - def self.latest_candidates - recordings = Recording - .where('music_session_id IS NOT NULL') - .order('created_at DESC') - .limit(10) - sessions = MusicSession - .where("music_sessions.id NOT IN ('#{recordings.map(&:music_session_id).join("','")}')") - .order('created_at DESC') - .limit(10) - latests = (recordings + sessions).sort { |o1,o2| o2.created_at <=> o1.created_at } - latests.collect do |ll| - nm = if ll.is_a?(Recording) - "#{ll.class.name.demodulize}: #{ll.band.present? ? ll.band.name : ll.owner.name}" - else - "#{ll.class.name.demodulize}: #{ll.band.present? ? ll.band.name : ll.creator.name}" - end - { :name => nm, :id => ll.id, :record => ll } - end + self.latest if self.latest.is_a? Recording end def self.create_with_params(params) @@ -118,8 +100,8 @@ class JamRuby::PromoLatest < JamRuby::Promotional def update_with_params(params) if (latest_id = params[:latest_id]).present? - self.latest = Recording.where(:id => latest_id).limit(1).all[0] || - MusicSession.where(:id => latest_id).limit(1).all[0] + self.latest = Recording.where(:id => latest_id).limit(1).first || + MusicSessionHistory.where(:id => latest_id).limit(1).first end self.position = params[:position] self.aasm_state = params[:aasm_state] @@ -131,7 +113,7 @@ class JamRuby::PromoLatest < JamRuby::Promotional nm = if ll.is_a?(Recording) ll.band.present? ? ll.band.name : ll.owner.name else - ll.band.present? ? ll.band.name : ll.creator.name + ll.band.present? ? ll.band.name : ll.user.name end "#{ll.class.name.demodulize}: #{nm} (#{ll.created_at})" end diff --git a/web/app/controllers/users_controller.rb b/web/app/controllers/users_controller.rb index fa26ef533..0c3afbac2 100644 --- a/web/app/controllers/users_controller.rb +++ b/web/app/controllers/users_controller.rb @@ -206,10 +206,10 @@ class UsersController < ApplicationController Slide.new("bands", "web/carousel_bands.jpg", "http://www.youtube.com/embed/eaYNM7p6Z5s") ] - @promo_buzz = Promotional.where(:type => 'JamRuby::PromoBuzz', :aasm_state => :active).where('latest_id IS NOT NULL').order(:position) + @promo_buzz = PromoBuzz.active if Rails.application.config.use_promos_on_homepage - @promo_latest = Promotional.where(:type => 'JamRuby::PromoLatest', :aasm_state => :active).where('latest_id IS NOT NULL').order(:position).limit(10) + @promo_latest = PromoLatest.active else @promo_latest, start = Feed.index(nil, limit: 10) end diff --git a/web/config/application.rb b/web/config/application.rb index e8340ef5b..5d46abe26 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -213,6 +213,6 @@ if defined?(Bundler) config.send_join_session_email_notifications = true - config.use_promos_on_homepage = false + config.use_promos_on_homepage = true end end