Module Slantwise::Acts::Selectable::ClassMethods
In: vendor/plugins/acts_as_selectable/lib/acts_as_selectable.rb

Methods

Public Instance methods

Include this in your ActiveRecord class to create a class method called select_options that you can use in your views to populate a select tag.

  class Thingy < ActiveRecord::Base
    acts_as_selectable
  end

Options:

  • :name_field => ‘column_name‘: this is the name of the column that stores the value to show to the user in the select box. Default: ‘name‘
  • :id_field => ‘my_id‘: this is the name of the column that stores the ID used to look up the record. Default: ‘id‘

[Source]

    # File vendor/plugins/acts_as_selectable/lib/acts_as_selectable.rb, line 20
20:         def acts_as_selectable(options = {})
21:           
22:           @custom_find_method = options[:find_with]
23:           
24:           if options[:name_field]
25:             @name_field = options[:name_field]
26:           else
27:             @name_field = 'name'
28:           end
29:           
30:           if options[:id_field]
31:             @id_field = options[:id_field]
32:           else
33:             @id_field = 'id'
34:           end
35:           
36:         end

Call in your views to create a select box, like this:

 f.select :things, Thing.select_options

[Source]

    # File vendor/plugins/acts_as_selectable/lib/acts_as_selectable.rb, line 40
40:         def select_options
41:           find_records.map {|r| [r.send(@name_field), r.send(@id_field)]}
42:         end

[Validate]