Merge pull request #308 from barriault/master

Remove direction select control from sort_select form builder
This commit is contained in:
Ryan Bigg 2013-11-27 15:48:31 -08:00
commit af8895cab6
1 changed files with 21 additions and 5 deletions

View File

@ -34,8 +34,13 @@ module Ransack
)
end
end
def sort_select(options = {}, html_options = {})
sort_attribute_select(options, html_options) +
sort_direction_select(options, html_options)
end
def sort_attribute_select(options = {}, html_options = {})
raise ArgumentError, "sort_select must be called inside a search FormBuilder!" unless object.respond_to?(:context)
options[:include_blank] = true unless options.has_key?(:include_blank)
bases = [''] + association_array(options[:associations])
@ -43,16 +48,27 @@ module Ransack
@template.grouped_collection_select(
@object_name, :name, sortable_attribute_collection_for_bases(bases), :last, :first, :first, :last,
objectify_options(options), @default_options.merge(html_options)
) + @template.collection_select(
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
objectify_options(options), @default_options.merge(html_options)
)
else
collection = sortable_attribute_collection_for_base(bases.first)
@template.collection_select(
@object_name, :name, collection, :first, :last,
objectify_options(options), @default_options.merge(html_options)
) + @template.collection_select(
)
end
end
def sort_direction_select(options = {}, html_options = {})
raise ArgumentError, "sort_direction must be called inside a search FormBuilder!" unless object.respond_to?(:context)
bases = [''] + association_array(options[:associations])
if bases.size > 1
@template.collection_select(
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
objectify_options(options), @default_options.merge(html_options)
)
else
collection = sortable_attribute_collection_for_base(bases.first)
@template.collection_select(
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
objectify_options(options), @default_options.merge(html_options)
)