when the search gets submitted it only returns results for records that
had
the searched value in publicists
from my model:
def self.search(search)
where(“headline LIKE ?”, “%#{search}%”)
where(“storyline LIKE ?”, “%#{search}%”)
where(“publicist LIKE ?”, “%#{search}%”)
end
from my controller:
def index
if params[:search] @press_releases =
PressRelease.search(params[:search]).order(“dateline
DESC”)
else @press_releases = PressRelease.order(“dateline DESC”)
end
end
when the search gets submitted it only returns results for records that had
the searched value in publicists
from my model:
def self.search(search)
where(“headline LIKE ?”, “%#{search}%”)
where(“storyline LIKE ?”, “%#{search}%”)
where(“publicist LIKE ?”, “%#{search}%”)
end
The where method returns a set of matching records, your method runs
the first where() and throws the result away, then it does the same
with the second and throws the result away, then it runs the third and
returns that. You presumably wish to find records where any of three
are true so you need to use something like
where((“headline LIKE ? OR storyline LIKE ? OR publicist LIKE ?”,
“%#{search}%”, “%#{search}%”, “%#{search}%”)
Thanks Colin, the person who posted that code sure had me fooled, i
could
have done better myself without adding code to the model It looked like
an
advanced technique, who would have guessed it was so wrong
Thanks Colin, the person who posted that code sure had me fooled, i could
have done better myself without adding code to the model It looked like an
advanced technique, who would have guessed it was so wrong
Where did you see it posted? Have you still got the link?