我试图创造我的搜索条件,但我遇到了一些麻烦。
这是我正在尝试创建的方法。
def self.searchadv(title, place, category, date)
!title.blank? ? conditions = ['title LIKE ?', "%#{title}%"] : conditions = []
if conditions
!place.blank? ? conditions << [' AND place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND date LIKE ?', "%#{place}%"] : conditions << []
else
!place.blank? ? conditions << [' place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' date LIKE ?', "%#{place}%"] : conditions << []
end
find(:all, :conditions => conditions)
end
它有效,直到我尝试附加 place 参数并收到此错误
错误数量的绑定变量(4 为 1)在:title LIKE ?
如果我删除这个:
if conditions
!place.blank? ? conditions << [' AND place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND date LIKE ?', "%#{place}%"] : conditions << []
else
!place.blank? ? conditions << [' place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' date LIKE ?', "%#{place}%"] : conditions << []
end
一切都很好,但我需要其他选项来创建我的搜索,我不明白为什么错误出现在“LiKE”中
有人可以帮助我吗?
提前致谢!