Last active
January 2, 2016 01:39
-
-
Save acrogenesis/8231487 to your computer and use it in GitHub Desktop.
Railscasts Search, Sort, Paginate, AJAX with Bootstrap 2
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
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 |
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
<%= 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