refactor channel rankings

This commit is contained in:
Lee Lawlor
2014-08-01 15:23:28 -04:00
parent a4daedbfbc
commit acd42142dc
34 changed files with 273 additions and 35 deletions

View File

@ -260,11 +260,7 @@ class ApplicationController < ActionController::Base
def get_channel_data
@channel = current_user.channels.find(params[:channel_id]) if params[:channel_id]
@channel = current_user.channels.find(params[:id]) if @channel.nil? and params[:id]
if @channel.ranking.blank?
@channel.ranking = @channel.calc_ranking
end
@channel.ranking = @channel.set_ranking if @channel.ranking.blank?
@key = @channel.api_keys.write_keys.first.try(:api_key) || ""
end

View File

@ -177,7 +177,6 @@ class ChannelsController < ApplicationController
get_channel_data
end
def update
# get the current user or find the user via their api key
@user = current_user || User.find_by_api_key(get_apikey)
@ -195,6 +194,7 @@ class ChannelsController < ApplicationController
@channel.assign_attributes(channel_params)
@channel.set_windows
@channel.save
@channel.set_ranking
else
session[:errors] = @channel.errors
redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return
@ -221,6 +221,7 @@ class ChannelsController < ApplicationController
channel.save
channel.save_tags(params[:channel][:tags]) if params[:channel][:tags].present?
channel.add_write_api_key
channel.set_ranking
@channel_id = channel.id
respond_to do |format|
format.json { render :json => channel.to_json(Channel.private_options) }