Class: Decidim::Initiatives::InitiativeTypesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/decidim/initiatives/initiative_types_controller.rb

Overview

Exposes the initiative type text search so users can choose a type writing its name.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #permissions_context

Instance Method Details

#searchObject

GET /initiative_types/search



8
9
10
11
12
13
# File 'app/controllers/decidim/initiatives/initiative_types_controller.rb', line 8

def search
  enforce_permission_to :search, :initiative_type

  types = FreetextInitiativeTypes.for(current_organization, I18n.locale, params[:term])
  render json: { results: types.map { |type| { id: type.id.to_s, text: type.title[I18n.locale.to_s] } } }
end