Module: Sphinxsearchlogic::RailsHelpers
- Defined in:
- lib/rails_helpers.rb
Instance Method Summary collapse
-
#order(search, options = {}, html_options = {}) ⇒ Object
Similar to the Searchlogic order helper.
-
#sphinxsearchlogic_form_for(*args, &block) ⇒ Object
Creates a form with a :search scope.
Instance Method Details
#order(search, options = {}, html_options = {}) ⇒ Object
Similar to the Searchlogic order helper.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails_helpers.rb', line 18 def order(search, = {}, = {}) [:params_scope] ||= :search [:as] ||= [:by].to_s.humanize [:ascend_scope] ||= "ascend_by_#{[:by]}" [:descend_scope] ||= "descend_by_#{[:by]}" ascending = search.order.to_s == [:ascend_scope] new_scope = ascending ? [:descend_scope] : [:ascend_scope] selected = [[:ascend_scope], [:descend_scope]].include?(search.order.to_s) if selected css_classes = [:class] ? [:class].split(" ") : [] if ascending [:as] = "▲ #{[:as]}" css_classes << "ascending" else [:as] = "▼ #{[:as]}" css_classes << "descending" end [:class] = css_classes.join(" ") end params = controller.params.dup # Stopped using clone, see http://github.com/joost/sphinxsearchlogic/issues#issue/3 params[[:params_scope]] ||= {} params[[:params_scope]].merge!(:order => new_scope) = {:controller => params[:controller], :action => params[:action], [:params_scope] => params[[:params_scope]]} link_to([:as], , ) end |
#sphinxsearchlogic_form_for(*args, &block) ⇒ Object
Creates a form with a :search scope. Use to create search form in your views.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rails_helpers.rb', line 5 def sphinxsearchlogic_form_for(*args, &block) if search_obj = args.find { |arg| arg.is_a?(Sphinxsearchlogic::Search) } = args. [:html] ||= {} [:html][:method] ||= :get [:url] ||= url_for args.unshift(:search) if args.first == search_obj args << end form_for(*args, &block) end |