Skip to content

Instantly share code, notes, and snippets.

@davidray
Created August 14, 2009 21:12
Show Gist options
  • Save davidray/168105 to your computer and use it in GitHub Desktop.
Save davidray/168105 to your computer and use it in GitHub Desktop.
def index
# Queries are here for clarity purposes in this demo
# It's of course a better idea to create a method in your model
users = User.find(:all) do
if params[:_search] == "true"
pseudo =~ "%#{params[:pseudo]}%" if params[:pseudo].present?
firstname =~ "%#{params[:firstname]}%" if params[:firstname].present?
lastname =~ "%#{params[:lastname]}%" if params[:lastname].present?
email =~ "%#{params[:email]}%" if params[:email].present?
role =~ "%#{params[:role]}%" if params[:role].present?
end
paginate :page => params[:page], :per_page => params[:rows]
order_by "#{params[:sidx]} #{params[:sord]}"
end
if request.xhr?
render :json => users.to_jqgrid_json([:id,:pseudo,:firstname,:lastname,:email,:role], params[:page], params[:rows], users.total_entries) and return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment