Question

So, I found this: Searchlogic OR condition results in undefined method

But that only works for fields on the model your are searching on directly. I have a suscription model, but I want to search over the different subscriptions' account names OR their other_field, for example.

from the above link (and modified) I'd like to be able to do something similar to this:

  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"
    }}

but now I get an error on this:

27:     <% form_for @search do |f| %>  

undefined method `subscription_subscription_path' for #<ActionView::Base:0x11061dbc0>

EDIT: figured it out: had to include .search in my call for assignment of the @search var

@search = Subscription.search.account_name_full_domain_like(term)
Was it helpful?

Solution

Provided your named scope is on your Subscription model, you will be returning subscription records. Your condition and join seem to be valid. I am not sure what the relationship of this named scope is to the instance variable @search you seem to be using in your view.

Is the path 'subscription_subscription_path' where you were expecting to submit this form to? If so, run "rake routes", and ensure that you have a path named 'subscription_subscription_path'.

If you want to submit to an alternate path, you can specify the url to submit to in form_for by doing something like the following:

<% form_for @search, :url => subscription_path(@search) %>

More information on specifying a URL for form_for can be found here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top