Created
February 24, 2012 22:03
-
-
Save hunterbridges/1904078 to your computer and use it in GitHub Desktop.
ghetto.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
if admin? | |
@orders = Gift.available.redeemed | |
@orders = @orders.includes(:redemption_product => [:vendor], :redemption_shipping_address => []) | |
else | |
@orders = current_vendor.purchased_gifts | |
end | |
@orders = @orders.with_aging if params[:sort].present? and params[:sort] == 'aging' | |
@orders = @orders.order("#{params[:sort]} #{params[:dir]}") if params[:sort].present? | |
base_q = @orders | |
@orders = @orders.offset(params[:offset].to_i) if params[:offset].present? | |
@orders = @orders.limit(params[:limit].to_i) if params[:limit].present? | |
if params[:seek].present? | |
query = @orders | |
result = query.all | |
@orders = result | |
found = @orders.find_index { |s| s.id == params[:seek].to_i } | |
length = result.length | |
while !found and length | |
query = base_q.offset(params[:offset].to_i + @orders.length).limit(params[:limit].to_i) | |
result = query.all | |
@orders = @orders.concat(result) | |
found = @orders.find_index { |s| s.id == params[:seek].to_i } | |
length = result.length | |
end | |
end | |
@orders = @orders.map { |order| order.as_vendor_json } | |
respond_to do |format| | |
format.csv | |
format.html | |
format.xml { render :xml => @orders } | |
format.json { render :json => @orders } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment