Skip to content
dennisbulgatz edited this page May 22, 2024 · 7 revisions

Preparing

Make sure you are including jQuery or Prototype.

Install

Add 'recordselect' to the Gemfile.

Then add the CSS and JavaScript to the application.js and application.css with require record_select (if you are using ActiveScaffold, the bridge will add them with require active_scaffold)

Enable and configure it on a controller.

class UsersController < ApplicationController
  record_select :per_page => 5, :search_on => 'username'
end

OR...
class UsersController < ApplicationController
    record_select search_on: [:username, :first_name, :last_name, :email],
      order_by: 'last_name ASC, first_name ASC',
      :toggle_search_mode => true,
      label: proc { |u| "#{u.first_name} #{u.last_name} (#{u.username})" }
...

  def record_select_model
    logged_user = current_user(params[:ignore_impersonated].present?)
    
    if params[:action_actionee]
      User.has_assigned_actions.distinct
    elsif params[:action_assigned_by]
      User.has_delegated_actions.distinct
    elsif logged_user.can_impersonate_anyone?
      super      
    else
      User.managed_by(logged_user.username).or(User.where(id: logged_user))
    end
  end
end
  1. Add the following to your routes.rb:
resources :model_id do
  record_select_routes
end

OR...

 resources :users, concerns: :active_scaffold do
    record_select_routes
    member do
      post 'update_skills'
    end
    collection do
      post 'sync_users'
    end
  end
  1. Now go ahead and use it somewhere.
class ActionsController < ApplicationController
  active_scaffold :"action" do |conf|
    conf.columns[:actionee].search_ui = :record_select, {params: {action_actionee: 'true'}}
  end

IF you are using a parameter so RS filters the returned results, that param needs to be permitted in a helper. The concat is do address that you could be adding permitted params in multiple helpers, and do not want to overwrite.

module ActionsHelper
  def permit_rs_browse_params
    (super || []).concat [:action_actionee, :action_assigned_by]
  end
Clone this wiki locally