Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds a route_proxy option #9

Merged
merged 1 commit into from

2 participants

@tvdeyen

Adds a route_proxy option, so it can be used in namespace isolated engines.

@dadooda
Owner

Tom

Thanks for the contribution. Have you actually used the feature you've implemented?

@dadooda dadooda merged commit d60f91a into from
@tvdeyen tvdeyen deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 3 deletions.
  1. +15 −3 lib/handles/sortable_columns.rb
View
18 lib/handles/sortable_columns.rb
@@ -10,7 +10,7 @@ module Handles #:nodoc:
# class MyController < ApplicationController
# handles_sortable_columns
# ...
- #
+ #
# In a view, mark up sortable columns by using the <tt>sortable_column</tt> helper:
#
# <%= sortable_column "Product" %>
@@ -185,6 +185,8 @@ def sortable_column(title, options = {}) #:doc:
o[k = :direction] = options.delete(k).to_s.downcase =~ /\Adesc\z/ ? :desc : :asc
o[k = :link_class] = options.delete(k) || sortable_columns_config[k]
o[k = :link_style] = options.delete(k)
+ o[k = :link_style] = options.delete(k)
+ o[k = :route_proxy] = options.delete(k)
#HELP /sortable_column
raise "Unknown option(s): #{options.inspect}" if not options.empty?
@@ -215,7 +217,12 @@ def sortable_column(title, options = {}) #:doc:
# Already sorted?
if pp[:column] == o[:column].to_s
- pcs << tpl.link_to(title, params.merge({conf[:sort_param] => [("-" if pp[:direction] == :asc), o[:column]].join, conf[:page_param] => 1}), html_options) # Opposite sort order when clicked.
+ if o[:route_proxy]
+ url = o[:route_proxy].send(:url_for, params.merge({conf[:sort_param] => [("-" if pp[:direction] == :asc), o[:column]].join, conf[:page_param] => 1}))
+ else
+ url = url_for(params.merge({conf[:sort_param] => [("-" if pp[:direction] == :asc), o[:column]].join, conf[:page_param] => 1}))
+ end
+ pcs << tpl.link_to(title, url, html_options) # Opposite sort order when clicked.
# Append indicator, if configured.
if (s = conf[:indicator_text][pp[:direction]]).present?
@@ -223,7 +230,12 @@ def sortable_column(title, options = {}) #:doc:
end
else
# Not sorted.
- pcs << tpl.link_to(title, params.merge({conf[:sort_param] => [("-" if o[:direction] != :asc), o[:column]].join, conf[:page_param] => 1}), html_options)
+ if o[:route_proxy]
+ url = o[:route_proxy].send(:url_for, params.merge({conf[:sort_param] => [("-" if o[:direction] != :asc), o[:column]].join, conf[:page_param] => 1}))
+ else
+ url = url_for(params.merge({conf[:sort_param] => [("-" if o[:direction] != :asc), o[:column]].join, conf[:page_param] => 1}))
+ end
+ pcs << tpl.link_to(title, url, html_options)
end
# For Rails 3 provide #html_safe.
Something went wrong with that request. Please try again.