Sha256: d9bde795faea77e3c34b141c30cac731cee5a2e8b918a14a864f839a40a3086e
Contents?: true
Size: 1.01 KB
Versions: 6
Compression:
Stored size: 1.01 KB
Contents
# -*- encoding : utf-8 -*- ## # Class: AutocompleteSerializer # # Creates hash (ready for JSON serialization) with # pairs of id => value to show in the autocomplete # select UI. # # The output format of to_json is optimized for 'Select2' # autocomplete UI. # # It would generate JSON of models :id and :text. Text is determined by # #to_autocomplete method, or by #to_s. module Autocomplete class BaseSerializer include RademadeAdmin::UriHelper def initialize(collection) @collection = collection end def as_json build_json end # args are left for backward compatibility # to Rails :json renderer def to_json(*args) as_json.to_json end protected def item_to_json(item) { :id => item.id.to_s, :text => (item.respond_to?(:to_autocomplete) ? item.to_autocomplete : item.to_s), :edit_url => admin_edit_form_uri(item) } end private def build_json @collection.map { |item| item_to_json(item) } end end end
Version data entries
6 entries across 6 versions & 1 rubygems