On 7 December 2015 at 16:15, fugee ohu <
fuge...@gmail.com> wrote:
> 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
>
> On Monday, December 7, 2015 at 9:17:13 AM UTC-5, Colin Law wrote:
>>
>> On 7 December 2015 at 13:55, fugee ohu <
fuge...@gmail.com> wrote:
>> > 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}%")
>>
>> Colin
>