Skip to content

Instantly share code, notes, and snippets.

@Veejay
Created August 7, 2010 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Veejay/513130 to your computer and use it in GitHub Desktop.
Save Veejay/513130 to your computer and use it in GitHub Desktop.
class PhotosController < ApplicationController
layout "photos"
def moderate
start = PhotoCursor.instance.profile_photos_cursor
@primary = params[:other].blank?
@photos = RemotePhoto.get(:next, :start => start, :limit => PhotoCursor::SET_SIZE, :profile_photo => @primary)
if request.post?
RemotePhoto.put(:bulk_update, {:photos => params[:photos]})
update_moderation_stats(params[:photos])
render :partial => "photos"
end
end
def rejected
@photos = RemotePhoto.get(:rejected)
# We want to render a different partial here, complete with pagination
render :moderate
end
def approved
@photos = RemotePhoto.get(:approved)
# We want to render a different partial here, complete with pagination
render :moderate
end
private
# Hate me all you can, but ActiveRecord can simply not handle that kind of scenario without raping performance
def update_moderation_stats(photos)
query = "INSERT INTO moderation_statistics (photo_id, moderator_id, approved, created_at, updated_at) VALUES "
values = []
photos.each do |k,v|
values << "(#{k}, 1, #{v}, NOW(), NOW())"
end
ActiveRecord::Base.connection.execute(query << values.join(","))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment