Search on multiple keywords in a single search text field (RAILS)

前端 未结 3 758
你的背包
你的背包 2020-12-18 11:12

I\'m fairly new and playing around with searching databases in Rails. I have a model and database that has a list of names under the \'name\' attribute. I want to be able to

3条回答
  •  醉话见心
    2020-12-18 11:50

    formatted_columns = format_column_names(Sub.column_names)
    where(formatted_columns.map {|cn| "#{cn} like ?" }.join("or "), *(["%#{search}%"] * formatted_columns.size))
    

    this takes care of all columns as well as the correct amount of fields

提交回复
热议问题