Last active
December 25, 2015 21:39
-
-
Save bayendor/7044025 to your computer and use it in GitHub Desktop.
Code to display the SQL query from an ActiveRecord Search & to limit number of results returned. From the ransack gem demo.
This file contains 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
<p>SQL: <%= @users.to_sql %></p> | |
<h2>Your first #{search_limit} results</h2> | |
<table> | |
<thead> | |
<th><%= sort_link @search, :id, {}, :method => action_name == 'advanced_search' ? :post : :get %></th> | |
<th><%= sort_link @search, :first_name, {}, :method => action_name == 'advanced_search' ? :post : :get %></th> | |
# ... | |
</thead> | |
<tbody> | |
<% @users.limit(search_limit).each do |user| %> | |
<tr> | |
<td><%= user.id %></td> | |
<td><%= user.first_name %></td> | |
# ... | |
</tr> | |
<% end %> | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment