#35 ✓resolved
Timobx

undefined method `new_search'

Reported by Timobx | December 3rd, 2008 @ 06:01 PM

Hi,

I am trying your example word for word because it would be useful to my project. However, I am getting this error message:

undefined method new_search' for #<Class:0x47eb3d8>

Full Trace says:

C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in method_missing' app/controllers/users_controller.rb:3:inindex' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in send' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:inperform_action_without_filters' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in call_filters' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:inperform_action_without_benchmark' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' C:/rubyinst/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:inperform_action_without_caching' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in perform_action' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:incache' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in cache' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:inperform_action' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in send' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:inprocess_without_filters' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in process_without_session_management_support' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:inprocess' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in process' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:inhandle_request' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in dispatch' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:indispatch_cgi' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in dispatch' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:inprocess' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in synchronize' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:inprocess' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in process_client' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:ineach' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in process_client' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:inrun' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in initialize' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:innew' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:ininitialize' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in new' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:inrun' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in run' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:ineach' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in run' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:inrun' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in run' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281 C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:innew_constants_in' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require' C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:inrequire' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:inrequire' C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire' script/server:3

I have spent a couple of days trying to debug but so far no luck. Any help is appreciated

Thanks

Tim

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 06:02 PM

    • State changed from “new” to “open”

    Can you give the contents of your controller action that is causing this?

  • Timobx

    Timobx December 3rd, 2008 @ 06:17 PM

    Thanks for the response.... It is exactly as in your example, I even cut and pasted it :) but here it is again

    @search = User.new_search(params[:search])

        @users, @users_count = @search.all, @search.count
    
    

    On a related note, I thought it was because the gem was not being configured so I removed the config.gem in the environment.rb, started the served, stopped it, added the line back and tried to restart the server and now I am not able to start the server!!!

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 06:20 PM

    Well searchlogic doesnt create files or change anything permanently, obviously. Something is really strange about your problem. I know hundreds of people are using this without any problems. What version of rails are you running? Do you have a lot of other unusual plugins installed that may be conflicting?

  • Timobx

    Timobx December 3rd, 2008 @ 06:26 PM

    Version of the rails is 2.0.2

    I do not have many plugins at all... I however, think there is something wrong with the config.gem "searchlogic" within the environment file... The reason being, if I remove it I get the original error for which I created the ticket. If I add it (now), the server does not start and gives me the following:

    C:/rubyinst/rails_apps/shopperu/config/environment.rb:17: private method gem' called for #<Rails::Configuration:0x31b0064> (NoMethodError)

        from C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:47:in `run'
        from C:/rubyinst/rails_apps/shopperu/config/environment.rb:15
        from C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
        from C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
        from C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
        from C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:147:in `rails'
         ... 20 levels...
        from C:/rubyinst/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
        from C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from C:/rubyinst/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from script/server:3
    
    

    Thanks in advance

    Tim

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 06:29 PM

    Yeah rails 2.0.X has some gem dependency issues. Try removing the gem line and installing it as a plugin.

  • Timobx

    Timobx December 3rd, 2008 @ 06:42 PM

    hmmmm using script/plugin install git://github.com/binarylogic/searchlogic.git I get another error message... Plugin not found

    Things not going my way I am afraid...

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 06:45 PM

    Ha ha, well the plugin is definitely there. Can you download it as a zip and install the plugin manually? This does seem strange though.

  • Timobx

    Timobx December 3rd, 2008 @ 06:51 PM

    Since I am upgrading Rails from 1.2 to 2 anyways, I am gonna upgrade Rails itself and see what happens... Is there a problem with 2.1.2 as well?

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 06:52 PM

    I don't believe so, you are the first person I have heard of having issues like this. Searchlogic should work just fine on rails 2.0.X

  • Timobx

    Timobx December 3rd, 2008 @ 06:56 PM

    Ok I will probably update Rails and try this tomorrow... Hopefully it will work, otherwise will have to use another Search and paginate plugin :( or something...

    Thanks

    Tim

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 06:58 PM

    I really don't think its searchlogic, the only thing i can do is help you out over a better means of communication, like AIM.

  • Timobx

    Timobx December 5th, 2008 @ 01:19 PM

    Hi Ben,

    Just FYI, upgraded to Rails 2.2.2 and now everything is working.

    Thanks for your help.

  • Timobx

    Timobx December 5th, 2008 @ 01:20 PM

    As a side note, is there a way in searchlogic to query multiple DB fields rather than just one? that would be ideal

    Tim

  • Ben Johnson

    Ben Johnson December 5th, 2008 @ 01:55 PM

    What do you mean, it can easily query multiple fields:

    search = User.new_search search.conditions.first_name_ends_with = "Ben" search.conditions.last_name_starts_with = "Whatever" search.all

  • Timobx

    Timobx December 5th, 2008 @ 02:15 PM

    I meant searching with the same condition on multple fields ie. for the SQL to be:

    Where first_name like 'ben' or last_name like 'ben' or email like 'ben'

    using the same search field

    Tim

  • Ben Johnson

    Ben Johnson December 5th, 2008 @ 02:17 PM

    Yeah, it really depends on how you are doing it. In my controller I have done something like:

    search = User.new_search(params[:search])
    search.conditions.last_name_like = search.conditions.email_like = search.conditions.first_name_like
    search.all
    

    So you only have the first_name_like field in your form and them force assign the other fields that use the same value.

  • Timobx

    Timobx December 5th, 2008 @ 05:22 PM

    I tried that but for some reason I get an error saying

    undefined local variable or method search' for ...

    in user Index

  • Ben Johnson

    Ben Johnson December 5th, 2008 @ 05:29 PM

    Yeah, you have to do it off of your search object, which is probably @search

  • Timobx

    Timobx December 5th, 2008 @ 05:39 PM

    Yeah this is what I did:

    @search = User.new_search(params[:search]) @search.conditions.first_name_like = search.conditions.last_name_like = =search.conditions.email_like @search.all

  • Ben Johnson

    Ben Johnson December 5th, 2008 @ 05:45 PM

    Yeah the successive searches need to have an @ in front of them

  • Timobx

    Timobx December 5th, 2008 @ 06:06 PM

    DOH!! sorry my bad... but now that I am not getting an error... this still does not seem to work it is still searching only the first_name field... sorry but I am being too dense today

  • Ben Johnson

    Ben Johnson December 5th, 2008 @ 06:26 PM

    Paste the contents of your controller action so I can see

  • Timobx

    Timobx December 5th, 2008 @ 06:38 PM

    class UsersController < ApplicationController

    def index

    @search = User.new_search(params[:search]) @search.conditions.email_like = @search.conditions.first_name_like = @search.conditions.last_name_like

    @search.all

    @users, @users_count = @search.all, @search.count

    end

    end

    index file below (Form)

    ===============================

    <% form_for @search do |f| %>

        <% f.fields_for @search.conditions do |users| %>
            <table align="center">
            <tr><td align="center">
            <%= users.text_field :first_name_keywords %></td>
            <td align="center"> <%= f.submit "Search" %></td></tr></table>
        <% end %>
    
    

    <% end %> ....

  • Ben Johnson

    Ben Johnson December 5th, 2008 @ 07:46 PM

    • State changed from “open” to “resolved”

    Your view need to use the "like" condition the last field, which would be last_name. Keywords and like are different, keywords cleans up the search, like does an exact search for that string. So your view field needs to reflect what you are doing in your controller.

  • Timobx

    Timobx December 10th, 2008 @ 12:50 PM

    Thanks for all your help. I tried your instructions, but it still does not work (i.e. the search of all the fields) It actually returns all the records rather than perform a search. Here is what I now have on my Form:

    <% f.fields_for @search.conditions do |users| %>

        <table align="center">
        <tr><td align="center">
        <%= users.text_field :last_name_like %></td>
        <td align="center"> <%= f.submit "Search" %></td></tr></table>
    <% end %>
    
    
  • Ben Johnson

    Ben Johnson December 12th, 2008 @ 12:57 AM

    Can you look in your logs and see what query it is executing? That is the best way to see what is going on behind the scenes. If you can look at the raw query it should be pretty easy to determine what the problem is.

  • Timobx

    Timobx December 12th, 2008 @ 03:47 PM

    Thank YOU!!! Yes that helped a lot. It is actually doing an AND rather than an OR that is:

    last_nm like '%BEN%' AND first_nm like '%BEN%' and since there are now rows like this, it doesn't return anything...

    I need to do an OR versus an AND

    Regards

    Tim

  • Ben Johnson

    Ben Johnson December 12th, 2008 @ 03:59 PM

    Either do:

    @search.any = true

    or

    @search.conditions_or_first_name_like

    etc.., prefix the condition with or or and and it will join it appropriately

  • Timobx

    Timobx December 15th, 2008 @ 12:57 PM

    Thanks but both of these give me a method error

  • Ben Johnson

    Ben Johnson December 15th, 2008 @ 01:02 PM

    Sorry, made a typo:

    @search.conditions.any = true

    or

    @search.conditions.or_first_name_like

  • Timobx

    Timobx December 15th, 2008 @ 01:30 PM

    Thank you. It finally worked :) sorry to have been such a pain but this code is a great tool, if you know how to use it.

    Thanks for all the help and support

  • Ben Johnson

    Ben Johnson December 15th, 2008 @ 01:34 PM

    No problem, the documentation covers all of this. If it is a useful tool for you it might be worth spending the time to read through the readme. For example, I love HAML, but I had to spend about 15 minutes reading through the docs, making a cheat sheet, etc, until I was used to using it. It helped a lot.

  • xijo (at gmx)

    xijo (at gmx) November 3rd, 2009 @ 10:38 AM

    @search.conditions.any = true or @search.conditions.or_first_name_like

    Hi there and sorry for burrowing old things, but is something like the quoted possible in SL2? Thanks and best regards, Joe

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Pages