Reputation: 1934
I am trying to implement jquery autocomplete categorized using rails.
I am able to report the following json response which look like this
["Air Canada to appeal Quebec court ruling on Aveos","First Nations meeting with PM in jeopardy","Neanderthals, humans may have missed each other","New York state enacts tougher gun control measures","Ontario high school teachers drop next week's walkout plan","test","Jean-Sebastien","Serge","Dean","feng","Heather","Carmen","Frank"]
his is a combination of user.firstname and article.titles and generated by the following response.
render :json => (@titles.map(&:title) || []) | (@cus.map(&:first_name) || [])
The problem is that this is good for the normal jquery autocomplete, but i am looking for the categorize and i am wondering how can i create the object with a label where the title is and where a category label would exist and i would insert "user" or "article" depending on the type of the object.
The idea is to have the following output for jquery categorise
{ label: "annttop C13", category: "Products" },
{ label: "anders andersson", category: "People" },
{ label: "andreas andersson", category: "People" },
{ label: "andreas johnson", category: "People" }
Upvotes: 0
Views: 94
Reputation: 29599
i don't see any fast way to do it but like this
@titles.map { |title| { label: title.title, category: 'Products' } } +
@cus.map { |cus| { label: cus.first_name, category: 'People' } }
Upvotes: 1