Hi,
I'm a noob to Rails, and I need some help. In Railscast 240, Ryan talks about
creating sortable table columns with ajax search:
http://railscasts.com/episodes/240-search-sort-paginate-with-ajax
However when I try to combine Thinking Sphinx rather then using the standard
search Ryan mentions, it breaks my sortable table columns. I'm sure there is a
quick way to fix this. Please help! Thanks :)
Here's my code:
MODEL:
define_index do
indexes :title, sortable: true
indexes :desc, sortable: true
indexes email
indexes :org, sortable: true
indexes org_percent
indexes :price, sortable:true
indexes :city, sortable: true
indexes :created_at, sortable: true
has created_at, updated_at
end
CONTROLLER:
helper_method :sort_column, :sort_direction
def index
@shruffles = Shruffle.order(sort_column + ' ' +
sort_direction).search(params[:search], :order => :created_at,
:sort_mode => :desc)
APPLICATION HELPER:
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 title, {:sort => column, :direction => direction}, {:class =>
css_class}
end
VIEW:
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<table class="pretty">
<tr align="left">
<th><%= sortable "title" %></th>
<th><%= sortable "price" %></th>
<th><%= sortable "city" %></th>
<th><%= sortable "org", 'Non-Profit' %></th>
<th><%= image_tag "ico-heart.png" %> <%= sortable "org_percent",
'Donation %' %></th>
<th><%= sortable "created_at", 'Date' %></th>
</tr>
<% for shruffle in @shruffles %>
<tr>
<td><%= link_to shruffle.title, shruffle %></td>
<td class="price"><%= number_to_currency(shruffle.price)
%></td>
<td><%= shruffle.city %></td>
<td><%= shruffle.org %></td>
<td><%= shruffle.org_percent %>%</td>
<td><%= shruffle.created_at.strftime("%b %d, %Y") %></td>
</tr>
<% end %>
</table>
-Frank
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/thinking-sphinx/-/Ls4y1X2qT5YJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.