foodsoft/app/controllers/foodcoop/ordergroups_controller.rb

23 lines
822 B
Ruby
Raw Normal View History

class Foodcoop::OrdergroupsController < ApplicationController
def index
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
@per_page = params[:per_page].to_i
else
@per_page = 20
end
2011-05-18 11:47:00 +02:00
@ordergroups = Ordergroup.order(:name.desc)
@ordergroups = @ordergroups.where(:name.matches => "%#{params[:query]}%") unless params[:query].blank? # Search by name
@ordergroups = @ordergroups.joins(:orders).where(:orders => {:starts.gte => Time.now.months_ago(3)}) if params[:only_active] # Select only active groups
2011-05-18 11:47:00 +02:00
@total = @ordergroups.size
@ordergroups = @ordergroups.paginate(:page => params[:page], :per_page => @per_page)
respond_to do |format|
format.html # index.html.erb
2011-05-18 11:47:00 +02:00
format.js { render :layout => false }
end
end
end