Record Select Integration (RecordSelect) - activescaffold/active_scaffold GitHub Wiki

In general using Record Select allows users to easily "search" for records to create associations. RecordSelect works well when the number of records to chose from is 50 or more, and a typical select (drop down) UI element becomes difficult to use.

An example: Let's say you wanted to create work-assignments. Work assignments belong to a user, and a task. In a system with ~1000 users and ~500 taks, using drop downs to find the user and the task is slow. Would rather be able to search for the user and task by name, and have the system "find" matches.

To setup record select is very easy.

Step 1. Add the record select gem to your Gemfile

git 'https://github.com/scambra/recordselect/', branch: 'master' do
  gem 'recordselect'
end

Step 2. Add the record_select configuration to the controller providing the link (associated record)

class UsersController < ApplicationController

  record_select :search_on => [:name, :samAccountName],
                :order_by => 'last_name ASC, first_name ASC',
                label: proc { |r| "#{r.name} | #{r.samAccountName}" }

Step 3. Specify that the column in the controller using the link

class WorkAssignmentsController < ApplicationController

  before_action :check_resource_permissions

  active_scaffold :"work_assignment" do |conf|
    conf.columns[:user].form_ui = :record_select
  end

record_select configuration options

The options you can pass are:

Syntax Description
model: the name of the model you want to expose. defaults based on the name of the controller
per_page: how many records to show per page when browsing
notify: a method name to invoke when a record has been selected, if you want server-side notification.
order_by: a SQL string to order the search results
search_on: a field name, or an array of field names. these fields will each be matched against each search term.
full_text_search: a boolean for whether to use a %?% search pattern or not. default is false.
label: a proc that accepts a record and returns a descriptive string. the default one calls :to_label on the record.
include: as for ActiveRecord::Base#find. can help with search conditions or just help optimize rendering the results.