所以,我找到了这个: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
@search = Subscription.search.account_name_full_domain_like(term)发布于 2011-09-08 23:12:02
如果您的命名作用域在您的订阅模型上,您将返回订阅记录。您的条件和联接似乎是有效的。我不确定这个命名作用域与您在视图中使用的实例变量@search之间的关系。
您希望将此表单提交到的路径是'subscription_subscription_path‘吗?如果是这样的话,运行"rake routes",并确保您有一个名为‘subscription_ path’的路径。
如果要提交到备用路径,可以通过执行以下操作在form_for中指定要提交到的url:
<% form_for @search, :url => subscription_path(@search) %>有关为form_for指定URL的更多信息可在此处找到:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for
https://stackoverflow.com/questions/7349285
复制相似问题