This named scope is working fine.
named_scope :search, lambda {|search_txt|
{
:conditions => ["field1 like ? or field2 like ? or field3 like ?","#{search_txt}%","#{search_txt}%","#{search_txt}%"]
}
}
Instead of writing search_txt three time in conditions. Can I handle the same scenario with passing search_txt only once in conditions ?
Something like
named_scope :search, lambda {|search_txt|
{
:conditions => ["field1 like ? or field2 like ? or field3 like ?","#{search_txt}%"]
}
}
I don’t know if this works in a scope, but there is another way to write conditions: