所以,我发现了这个:Searchlogic OR condition results in undefined method
但这仅适用于您直接搜索的模型上的字段。我有一个订阅模型,但我想搜索不同订阅的帐户名称或它们的 other_field,例如。
从上面的链接(和修改)我希望能够做类似的事情:
named_scope :account_name_full_domain_like, lambda{ |name|{
:conditions => ["accounts.name LIKE ? OR accounts.full_domain LIKE ?", "%" + name + "%", "%" + name + "%"],
:joins => "LEFT JOIN `accounts` ON `accounts`.id = `subscriptions`.account_id"
}}
但现在我得到一个错误:
27: <% form_for @search do |f| %>
undefined method `subscription_subscription_path' for #<ActionView::Base:0x11061dbc0>
编辑:想通了:必须在我的调用中包含 .search 来分配@search var
@search = Subscription.search.account_name_full_domain_like(term)