In form sorting using ransack gem not working
Asked Answered
L

1

0

I've been trying (unsuccessfully so far) to use the out of the box in-form sorting provided by the ransack gem, and the result of it unfortunately is an empty form.

Here's what I've done so far:

Controller:
    class LandingController < ApplicationController
      layout "landing2"
      def index
        @zones = Zone.all
        @zone_id ||= 1
        @q = Property.search(params[:q])
        @q.build_sort if @q.sorts.empty?
      end
    end

View (partial):

<%= search_form_for @q, :url => home_path, :html => { :method => :get } do |f| %>
  <%= f.sort_fields do |s| %>
    <%= s.sort_select %>
  <% end %>
  <%= f.submit "Sort" %>
<% end %>

And the result is:

Ransack sort form(empty)

Does anybody know what could possibly be wrong?

Thanks for all the help!

Luting answered 5/11, 2012 at 22:31 Comment(0)
C
2

In your controller you missed the line

@properties = @q.result(:distinct => true)

which should be after

@q = Property.search(params[:q])
Congruency answered 6/11, 2012 at 11:3 Comment(1)
Yeah! absolutely right ! Thanks for hearing my call for help ! :)Luting

© 2022 - 2024 — McMap. All rights reserved.