Module: ScopedSearch::Helpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/scoped_search.rb
Instance Method Summary collapse
- #form_for(record, *args, &block) ⇒ Object
-
#order_for_scoped_search(column, search_param = :search) ⇒ Object
TODO : refactor this ?.
Instance Method Details
#form_for(record, *args, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/scoped_search.rb', line 64 def form_for(record, *args, &block) if record.is_a?(ScopedSearch::Base) = args. .symbolize_keys! default_model_route = (polymorphic_path(record.model_class) rescue nil) .reverse_merge!({ :url => default_model_route, :as => :search }) raise "You have to manually specify :url in your form_for options..." unless [:url].present? [:html] ||= {} [:html].reverse_merge!({ :method => :get }) args << end super(record, *args, &block) end |
#order_for_scoped_search(column, search_param = :search) ⇒ Object
TODO : refactor this ?
84 85 86 87 88 89 90 91 92 |
# File 'lib/scoped_search.rb', line 84 def order_for_scoped_search(column, search_param = :search) search_order = params[search_param].present? && params[search_param]["ascend_by_#{column}"].present? ? { "descend_by_#{column}" => true } : { "ascend_by_#{column}" => true } params[search_param] ||= {} search_without_order = params[search_param].clone search_without_order.delete_if { |k,v| k.to_s.starts_with?("ascend_by") || k.to_s.starts_with?("descend_by") } params.merge(search_param => search_without_order.merge(search_order)) end |