Class: Engine2::TypeAheadAction
- Inherits:
-
DecodeAction
- Object
- Action
- DecodeAction
- Engine2::TypeAheadAction
- 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, #fields, #fields!, #hide_fields, #loc!, #render, #show_fields
Methods included from ActionModelSupport
#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_anonymous_action_class, #check_static_action, #define_invoke, #define_method, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #join_keys, #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
#case_insensitive ⇒ Object
74 75 76 |
# File 'lib/engine2/action/decode.rb', line 74 def case_insensitive @case_insensitive = true end |
#invoke(handler) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/engine2/action/decode.rb', line 78 def invoke handler if query = handler.params[:query] condition = @meta[:decode_fields].map{|f|f.like("%#{query}%", case_insensitive: @case_insensitive)}.reduce{|q, f| q | f} {entries: get_query.where(condition).limit(@limit).load_all} else handler.permit id = handler.params[:id] record = get_query.load 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 @limit = lmt end |
#pre_run ⇒ Object
65 66 67 68 |
# File 'lib/engine2/action/decode.rb', line 65 def pre_run super @limit = 10 end |