Skip to content

Instantly share code, notes, and snippets.

@acrogenesis
Last active January 2, 2016 01:39
Show Gist options
  • Save acrogenesis/8231487 to your computer and use it in GitHub Desktop.
Save acrogenesis/8231487 to your computer and use it in GitHub Desktop.
Railscasts Search, Sort, Paginate, AJAX with Bootstrap 2
module ApplicationHelper
def sortable(column, title = nil)
title ||= column.titleize
css_class = column == sort_column ? "current #{sort_direction}" : nil
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
link_to (css_class ? title + direction_icon(direction) : title).html_safe, params.merge(:sort => column, :direction => direction, :page => nil), {:class => css_class}
end
private
def direction_icon(direction)
"<i class='#{direction == "desc" ? "icon-chevron-down" : "icon-chevron-up"}'></i>"
end
end
<%= form_tag products_path, :method => 'get', :id => "product_search", :class=>"form-search" do %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<%= text_field_tag :search, params[:search], :class=> "input-medium search-query" %>
<%= submit_tag "Search", :name => nil, :class=> "btn" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment