Class: Ransack::Helpers::FormHelper::SortLink

Inherits:
Object
  • Object
show all
Defined in:
lib/ransack/helpers/form_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(search, attribute, args, params) ⇒ SortLink

Returns a new instance of SortLink.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ransack/helpers/form_helper.rb', line 87

def initialize(search, attribute, args, params)
  @search         = search
  @params         = parameters_hash(params)
  @field          = attribute.to_s
  @sort_fields    = extract_sort_fields_and_mutate_args!(args).compact
  @current_dir    = existing_sort_direction
  @label_text     = extract_label_and_mutate_args!(args)
  @options        = extract_options_and_mutate_args!(args)
  @hide_indicator = @options.delete(:hide_indicator) ||
                    Ransack.options[:hide_sort_order_indicators]
  @default_order  = @options.delete :default_order
end

Instance Method Details

#html_options(args) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/ransack/helpers/form_helper.rb', line 113

def html_options(args)
  html_options = extract_options_and_mutate_args!(args)
  html_options.merge(
    class: [['sort_link'.freeze, @current_dir], html_options[:class]]
           .compact.join(' '.freeze)
  )
end

#nameObject



100
101
102
103
104
105
# File 'lib/ransack/helpers/form_helper.rb', line 100

def name
  [ERB::Util.h(@label_text), order_indicator]
  .compact
  .join(' '.freeze)
  .html_safe
end

#url_optionsObject



107
108
109
110
111
# File 'lib/ransack/helpers/form_helper.rb', line 107

def url_options
  @params.merge(
    @options.merge(
      @search.context.search_key => search_and_sort_params))
end