Last active
August 29, 2015 14:21
-
-
Save jasonong/6bc765ade3838c9ea7a0 to your computer and use it in GitHub Desktop.
Simple hash conditions for columns in model table.
This file contains hidden or 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
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