Rails 5连接两个属性以显示为JSON

时间:2017-11-16 12:36:28

标签: ruby-on-rails json ruby autocomplete ruby-on-rails-5

我将此方法作为自动填充文本字段的来源。

def index

@articulos = Articulo.where("descripcion ILIKE CONCAT('%',?,'%')",params[:term]).
or(Articulo.where("codigo ILIKE CONCAT('%',?,'%')",params[:term]))
render json: @articulos.map(&:descripcion)

end

此查询按说明或Codigo搜索,但JSON在自动填充字段中仅显示说明。我需要JSON在自动填充文本字段中显示连接的Codigo属性和描述,例如

34432 - descripcion del articulo

0 个答案:

没有答案