Class: TamSelectRemoteController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- TamSelectRemoteController
- Includes:
- TamSelectPaginatable
- Defined in:
- lib/generators/tam_select/templates/tam_select_remote_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.tam_select(model:, label:, value: :id, search_by: nil, per_page: 20) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/generators/tam_select/templates/tam_select_remote_controller.rb', line 6 def self.tam_select(model:, label:, value: :id, search_by: nil, per_page: 20) self.tam_select_config = { model: model, label: label, value: value, search_by: Array(search_by || label), per_page: per_page }.freeze end |
Instance Method Details
#index ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/tam_select/templates/tam_select_remote_controller.rb', line 16 def index config = self.class.tam_select_config raise "Configure #{self.class.name} with tam_select(...)" unless config records = search(tam_select_scope(config), config) render json: tam_select_payload( records, label: config[:label], value: config[:value], per_page: config[:per_page] ) end |