Find_by_sql help on site search

Hello,

Thanks for taking a look and offering up your help!

I’m trying to set up a way my site visitor can search my site via
band.name and videos.name simultaneously, for up to 10 results. The
names should be searched for any and all keywords entered. I think I’m
close, but my query doesn’t return any results for me, but I’m not
getting any errors.

Important Associations: band has_many videos while videos belongs_to
bands.

@search_b = search_terms.compact.join(" OR b.name LIKE “)
@search_v = search_terms.compact.join(” OR v.name LIKE ")
@results = Video.find_by_sql([“SELECT b.name, v.name FROM bands b,
videos v WHERE b.id = v.band_id AND v.name LIKE ? OR b.name LIKE ?”,
@search_v , @search_b])

RoR is my first language, so if my code seems inefficient, please don’t
be too harsh. :wink: I’m just trying to find a way to make it work.

Thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs