How to make a query with a wildcard search in Rails or SQL?

I have a table in which there is a pattern to search for files, example:

I receive a file file_1_2018-12-08.xlsx

How to make a request so I can give the full name of the file, and I had all the rows where the value of "file_1" contains in the file name?

I know how to do if the string value was the name of the file, but I have the template find the line. it's easy. But we must do the opposite.

PS, my project is on Rails. But if you write pure SQL code, that is also welcome)

P. P. S As I'm doing now:
I sorted all rows in the table and just compare the suitability of the pattern? It turns out me for one file I want to loop through all rows and make comparisons is equal to the count of rows. It's awful and I want to do the right thing, but what query do not understand.
March 23rd 20 at 19:00
1 answer
March 23rd 20 at 19:02
the first thing that came to mind
Table.where ("filename like concat('%%', pattern, '%%')", filename: 'filename4.xls')
# SELECT "tables".* FROM "tables" WHERE ('filename4.xls' like concat('%%', pattern, '%%'))

Find more questions by tags Ruby on RailsMySQL