Skip to content

Instantly share code, notes, and snippets.

@jasonong
Last active August 29, 2015 14:21
Show Gist options
  • Save jasonong/6bc765ade3838c9ea7a0 to your computer and use it in GitHub Desktop.
Save jasonong/6bc765ade3838c9ea7a0 to your computer and use it in GitHub Desktop.
Simple hash conditions for columns in model table.
sql = '1 = 1'
values = {}
if params[:foo].present?
sql << 'AND foo >= :foo'
values[:foo] = params[:foo]
end
if params[:bar].present?
sql << 'AND bar < :bar'
values[:bar] = params[:bar]
end
Homage.paginate(
...
:conditions => [sql, values]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment