简体   繁体   中英

Set key dynamically using jBuilder Elasticsearch with Rails

I want to enable the user to search using different fields from my model, for instance, a different field than name :

json.set!(:match, name: @term)

Is there a way to supply a value (string) instead of name: on the line above?

I am not sure I got your question, if you have instance vairable @key_value, it can be name or body or other attribute name. You could do the following:

json.set!(:match, @key_value => @term)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM