Sha256: 15bf2d205791461d890309d97df39338411fadfc35fa62f15a594aa6d9a9b81a

Contents?: true

Size: 1.87 KB

Versions: 56

Compression:

Stored size: 1.87 KB

Contents

module RecordSelect
  def self.included(base)
    base.send :extend, ClassMethods
  end

  module ClassMethods
    # Enables and configures RecordSelect on your controller.
    #
    # *Options*
    # +model+::     defaults based on the name of the controller
    # +per_page+::  records to show per page when browsing
    # +notify+::    a method name to invoke when a record has been selected.
    # +order_by+::  a SQL string to order the search results
    # +search_on+:: an array of searchable fields
    # +full_text_search+::  a boolean for whether to use a %?% search pattern or not. default is false.
    # +label+::     a proc that accepts a record as argument and returns an option label. default is to call record.to_label instead.
    # +include+::   as for ActiveRecord::Base#find. can help with search conditions or just help optimize rendering the results.
    # +link+::      a boolean for whether wrap the text returned by label in a link or not. default is true. set to false when
    #               label returns html code which can't be inside a tag. You can use record_select_link_to_select in your proc
    #               or partial to add a link to select action
    #
    # You may also pass a block, which will be used as options[:notify].
    def record_select(options = {})
      options[:model] ||= self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore
      @record_select_config = RecordSelect::Config.new(options.delete(:model), options)
      self.send :include, RecordSelect::Actions
      self.send :include, RecordSelect::Conditions
    end

    def record_select_config
      case
      when defined?(@record_select_config)
        @record_select_config
      when superclass.respond_to?(:record_select_config)
        superclass.record_select_config
      end
    end

    def uses_record_select?
      !record_select_config.nil?
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
recordselect-4.0.4 lib/record_select.rb
recordselect-4.0.3 lib/record_select.rb
recordselect-4.0.2 lib/record_select.rb
recordselect-4.0.1 lib/record_select.rb
recordselect-4.0.0 lib/record_select.rb
recordselect-3.10.9 lib/record_select.rb
recordselect-3.10.8 lib/record_select.rb
recordselect-3.10.7 lib/record_select.rb
recordselect-3.10.6 lib/record_select.rb
recordselect-3.10.5 lib/record_select.rb
recordselect-3.10.4 lib/record_select.rb
recordselect-3.10.3 lib/record_select.rb
recordselect-3.10.2 lib/record_select.rb
recordselect-3.10.1 lib/record_select.rb
recordselect-3.10.0 lib/record_select.rb
recordselect-3.9.2 lib/record_select.rb
recordselect-3.9.1 lib/record_select.rb
recordselect-3.9.0 lib/record_select.rb
recordselect-3.8.7 lib/record_select.rb
recordselect-3.8.6 lib/record_select.rb