David Ng
David Ng

Reputation: 470

Search for Name by #hashtag in ActiveRecord

I am developing with Ruby on Rails, want to know whether there is an efficient way to find a name matches a hashtag.

Input: #annrobinson

if there is a record name "Ann Robinson", it matches

if there are other records, like "Ann Robin Son" , "Annro Bin son", they fulfill the requirement too.

Many thanks!

Upvotes: 1

Views: 249

Answers (1)

Bachan Smruty
Bachan Smruty

Reputation: 5734

Suppose User is your model. Then you can get it by

User.where("CONCAT('#',LOWER(REPLACE(name, ' ', ''))) = ?", '#annrobinson')

Upvotes: 1

Related Questions