lib/searchlogic/rails_helpers.rb in binarylogic-searchlogic-2.0.1 vs lib/searchlogic/rails_helpers.rb in binarylogic-searchlogic-2.1.0
- old
+ new
@@ -4,10 +4,15 @@
# alternates between calling 2 named scopes: "ascend_by_*" and "descend_by_*"
#
# By default Searchlogic gives you these named scopes for all of your columns, but
# if you wanted to create your own, it will work with those too.
#
+ # Examples:
+ #
+ # order @search, :by => :username
+ # order @search, :by => :created_at, :as => "Created"
+ #
# This helper accepts the following options:
#
# * <tt>:by</tt> - the name of the named scope. This helper will prepend this value with "ascend_by_" and "descend_by_"
# * <tt>:as</tt> - the text used in the link, defaults to whatever is passed to :by
# * <tt>:ascend_scope</tt> - what scope to call for ascending the data, defaults to "ascend_by_:by"
@@ -30,19 +35,20 @@
options[:as] = "▼ #{options[:as]}"
css_classes << "descending"
end
html_options[:class] = css_classes.join(" ")
end
- link_to options[:as], url_for(options[:params_scope] => {:order => new_scope}), html_options
+ link_to options[:as], url_for(options[:params_scope] => search.conditions.merge( { :order => new_scope } ) ), html_options
end
# Automatically makes the form method :get if a Searchlogic::Search and sets
# the params scope to :search
def form_for(*args, &block)
if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
options = args.extract_options!
options[:html] ||= {}
options[:html][:method] ||= :get
+ options[:url] ||= url_for
args.unshift(:search) if args.first == search_obj
args << options
end
super
end
\ No newline at end of file