Skip to content

Instantly share code, notes, and snippets.

@bayendor
Last active December 25, 2015 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayendor/7044025 to your computer and use it in GitHub Desktop.
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.
<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