Cross Reference: autocomplete_controller.rb
xref
: /
ontohub
/
app
/
controllers
/
autocomplete_controller.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
autocomplete_controller.rb revision 7e3ffdd270e31d82db163acaf6d0849cb7dda0e8
class
AutocompleteController
<
ActionController
::
Base
MIN_LENGTH
=
3
def
index
term
=
params
[:
term
]
.to_s.strip
if
term.length
<
MIN_LENGTH
@
result
= []
else
autocomplete
=
Autocomplete.new
(
params
[:
scope
],
term
)
@
result
=
autocomplete.result.map
{|r|
{
id
:
r.id
,
type
:
r.class.to
_s
,
value
:
r.to
_s
}
}
end
render
:
json
=> @
result
rescue
Autocomplete
::
InvalidScope
=>
error
render
:
text
=>
error.message
, :
status
=> :
unprocessable_entity
end
end