我在搜索表单中使用了以下代码。我希望能够将作用域方法与 by_title 链接起来,但我看不到如何。我想将 by_title 作为一种方法,而不仅仅是这样做:
# Arel helpers
class << self
def by_city(city)
where(['city_id = ?', city])
end
def by_title(title)
where('title LIKE ?', "%#{title}%")
end
end
def self.search(search_params)
experiences = scoped
experiences.self.by_title(search_params[:title]) if search_params[:title]
end