Ruby on Rails Monday, December 7, 2015

On 7 December 2015 at 16:15, fugee ohu <fugee279@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

Where did you see it posted? Have you still got the link?

Colin

>
> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/cf20186b-6a84-4ecb-b0b2-f44603424b16%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsTD3Vc%2B%2BX6WVA44PnN4tkMFXERyL4XKSSVz9Mv4Zg1WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment