Class: Engine2::TypeAheadAction

Inherits:
DecodeAction show all
Defined in:
lib/engine2/action/decode.rb

Instance Attribute Summary

Attributes inherited from Action

#assets, #invokable, #meta, #node, #static

Instance Method Summary collapse

Methods inherited from DecodeAction

#decode, #post_process, #post_run, #separator, #show_max_selected

Methods included from ActionAPISupport

#config, #decorate, #field_filter, #hide_fields, #info, #info!, #loc!, #render, #show_fields

Methods included from ActionModelSupport

#get_type_info, #hide_pk, #node_defined, #show_pk, #unsupported_association

Methods included from ActionQuerySupport

#find_record, #get_query, #post_run, #query, #select

Methods inherited from Action

action_type, #action_type, #arguments, #check_static_action, #define_invoke, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #lookup, #merge, #node_defined, #post_process, #post_run, #repeat, #request, #request_action_proc_params, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Action

Instance Method Details

#invoke(handler) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/engine2/action/decode.rb', line 74

def invoke handler
    if query = handler.params[:query]
        condition = @meta[:decode_fields].map{|f|f.like("%#{query}%")}.reduce{|q, f| q | f}
        {entries: get_query.where(condition).limit(@meta[:limit]).all}
    else
        handler.permit id = handler.params[:id]
        record = get_query[Hash[assets[:model].primary_keys.zip(split_keys(id))]]
        # handler.halt_not_found(LOCS[:no_entry]) unless record
        {entry: record}
    end
end

#limit(lmt) ⇒ Object



70
71
72
# File 'lib/engine2/action/decode.rb', line 70

def limit lmt
    @meta[:limit] = lmt
end

#pre_runObject



65
66
67
68
# File 'lib/engine2/action/decode.rb', line 65

def pre_run
    super
    limit 10
end