Skip to content

Instantly share code, notes, and snippets.

@bradherman
Created June 27, 2012 07:48
Show Gist options
  • Save bradherman/3002282 to your computer and use it in GitHub Desktop.
Save bradherman/3002282 to your computer and use it in GitHub Desktop.
# typical route
get '/my_model' do
# return query results if search param, otherwise return all
if params[:relation_id]
MyModel.all(:relation_id => params[:relation_id], :order => :name.asc)
else
MyModel.all(:order => :name.asc)
end
end
# proposed change
get '/my_model' do
# a nil param returns all instead of all models with param set to nil
MyModel.all(:relation_id.nilcon => params[:relation_id], :order => :name.asc)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment