Module: Ransack::Helpers::FormHelper
- Defined in:
- lib/ransack/helpers/form_helper.rb
Defined Under Namespace
Classes: SortLink
Instance Method Summary collapse
-
#search_form_for(record, options = {}, &proc) ⇒ Object
search_form_for
. -
#sort_link(search_object, attribute, *args, &block) ⇒ Object
sort_link
. -
#sort_url(search_object, attribute, *args) ⇒ Object
sort_url
<%= sort_url(@q, :created_at, default_order: :desc) %>.
Instance Method Details
#search_form_for(record, options = {}, &proc) ⇒ Object
search_form_for
<%= search_form_for(@q) do |f| %>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ransack/helpers/form_helper.rb', line 9 def search_form_for(record, = {}, &proc) if record.is_a? Ransack::Search search = record [:url] ||= polymorphic_path( search.klass, format: .delete(:format) ) elsif record.is_a?(Array) && (search = record.detect { |o| o.is_a?(Ransack::Search) }) [:url] ||= polymorphic_path( (record), format: .delete(:format) ) else raise ArgumentError, 'No Ransack::Search object was provided to search_form_for!' end [:html] ||= {} = { class: html_option_for([:class], search), id: html_option_for([:id], search), method: :get } [:as] ||= Ransack.[:search_key] [:html].reverse_merge!() [:builder] ||= FormBuilder form_for(record, , &proc) end |
#sort_link(search_object, attribute, *args, &block) ⇒ Object
sort_link
<%= sort_link(@q, :name, [:name, 'kind ASC'], 'Player Name') %>
You can also use a block:
<%= sort_link(@q, :name, [:name, 'kind ASC']) do %>
<strong>Player Name</strong>
<% end %>
47 48 49 50 51 52 53 54 55 |
# File 'lib/ransack/helpers/form_helper.rb', line 47 def sort_link(search_object, attribute, *args, &block) search, routing_proxy = extract_search_and_routing_proxy(search_object) unless Search === search raise TypeError, 'First argument must be a Ransack::Search!' end args[args.first.is_a?(Array) ? 1 : 0, 0] = capture(&block) if block_given? s = SortLink.new(search, attribute, args, params, &block) link_to(s.name, url(routing_proxy, s.), s.(args)) end |
#sort_url(search_object, attribute, *args) ⇒ Object
sort_url
<%= sort_url(@q, :created_at, default_order: :desc) %>
60 61 62 63 64 65 66 67 |
# File 'lib/ransack/helpers/form_helper.rb', line 60 def sort_url(search_object, attribute, *args) search, routing_proxy = extract_search_and_routing_proxy(search_object) unless Search === search raise TypeError, 'First argument must be a Ransack::Search!' end s = SortLink.new(search, attribute, args, params) url(routing_proxy, s.) end |