mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 00:00:12 +01:00
let autocomplete fail gracefully when param is not set
This commit is contained in:
parent
05ba6060fc
commit
1a821a228f
3 changed files with 13 additions and 10 deletions
|
|
@ -128,9 +128,13 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def for_autocomplete(coll, substr)
|
||||
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
|
||||
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
|
||||
return json_elems == "[{}]" ? "" : json_elems
|
||||
if substr # protect agains empty request
|
||||
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
|
||||
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
|
||||
return json_elems == "[{}]" ? "" : json_elems
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
# Uses RedCloth to transform text using either Textile or Markdown Need to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue