Sha256: 291f9f734ae20d300262db9fc372546c4f16200c157a545557195277cdce61c0

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

module Ransack
  module Helpers
    module FormHelper
      def search_form_for(record, options = {}, &proc)
        if record.is_a?(Ransack::Search)
          search = record
          options[:url] ||= polymorphic_path(search.klass)
        elsif record.is_a?(Array) && (search = record.detect {|o| o.is_a?(Ransack::Search)})
          options[:url] ||= polymorphic_path(record.map {|o| o.is_a?(Ransack::Search) ? o.klass : o})
        else
          raise ArgumentError, "No Ransack::Search object was provided to search_form_for!"
        end
        options[:html] ||= {}
        html_options = {
          :class  => options[:as] ? "#{options[:as]}_search" : "#{search.klass.to_s.underscore}_search",
          :id => options[:as] ? "#{options[:as]}_search" : "#{search.klass.to_s.underscore}_search",
          :method => :get
        }
        options[:as] ||= 'q'
        options[:html].reverse_merge!(html_options)
        options[:builder] ||= FormBuilder

        form_for(record, options, &proc)
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ransack-0.5.4 lib/ransack/helpers/form_helper.rb
ransack-0.5.3 lib/ransack/helpers/form_helper.rb
ransack-0.5.2 lib/ransack/helpers/form_helper.rb
ransack-0.5.1 lib/ransack/helpers/form_helper.rb
ransack-0.5.0 lib/ransack/helpers/form_helper.rb
ransack-0.4.2 lib/ransack/helpers/form_helper.rb
ransack-0.4.1 lib/ransack/helpers/form_helper.rb
ransack-0.4.0 lib/ransack/helpers/form_helper.rb
ransack-0.3.0 lib/ransack/helpers/form_helper.rb
ransack-0.2.1 lib/ransack/helpers/form_helper.rb
ransack-0.2.0 lib/ransack/helpers/form_helper.rb