Problems when applying search to filter rows

Hello,
I am trying to create in the main Layout of the application fields of
selection of fields of the model, and other to insert its value. Next I
put
a search button, with the idea to leak by the search in the view of the
model where it executes this button. I have generated the views with
ajaxscaffold.
I do not know if what I try to do it does of this form or another one.

My code is the following one:

  • Main Layout application.rhtml:

    <%= form_tag :action => 'buscar' %>

    <%=_('Búsqueda en el campo:')%>  <%= options_for_select(@campostabla, @params[:search_field]) %>   <%=_('igual a:')%>  <input type="text" name="search_value" value="<%=@search_value%>"

    size=‘16’ id=‘search_value’/> 
    <%= submit_tag(_(‘Buscar’), :name=>‘op’)%> 
    <%= end_form_tag %>

    • Code in the controller Empresas_Controller.rb:

      def list
      @campostabla = Empresa.column_names #Para el campo búsqueda
      end

      Para el botón buscar (Search Button)

      def buscar
      @search_field = @params[‘search_field’]
      @search_value = @params[‘search_value’]
      Empresa.find(:all, :conditions => ["? = ?", @search_field,
      @search_value])
      render_action ‘list’
      end

    • When pressing the button search (Buscar), gives the following error
      me:

    NoMethodError in Empresas#buscar

    Showing app/views/layouts/application.rhtml where line #266 raised:

    You have a nil object when you didn’t expect it!
    You might have expected an instance of Array.
    The error occured while evaluating nil.inject

    Extracted source (around line #266):

    263:


    264: <%=(‘Búsqueda en el campo:’)%> 
    265:
    266: <%= options_for_select(@campostabla, @params[:search_field])
    %>
    267:  
    268: <%=
    (‘igual a:’)%> 
    269:  

    RAILS_ROOT: script/…/config/…
    Application Trace | Framework Trace | Full Trace

    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/form_options_helper.rb:114:in
    options_for_select' #{RAILS_ROOT}/app/views/layouts/application.rhtml:266:in_run_rhtml_layouts_application’
    lib/globalize/rails/action_view.rb:15:in render_file' #{RAILS_ROOT}/app/controllers/empresas_controller.rb:32:inbuscar’
    #{RAILS_ROOT}/app/controllers/application.rb:29:in process' #{RAILS_ROOT}/app/controllers/application.rb:28:incatch’
    #{RAILS_ROOT}/app/controllers/application.rb:28:in `process’

    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/form_options_helper.rb:114:in
    options_for_select' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:314:insend’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:314:in
    compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:290:inrender_template’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:249:in
    globalize_old_render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/layout.rb:249:inrender_with_a_layout’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:738:in
    render_with_layout' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:689:inrender_action’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in
    send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:inperform_action_without_filters’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in
    perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
    measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in
    perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:insend’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in
    process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:inprocess_without_session_management_support’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in
    process' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:indispatch’
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
    handle_dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:inservice’
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
    /usr/lib/ruby/1.8/webrick/server.rb:172:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:161:instart’
    /usr/lib/ruby/1.8/webrick/server.rb:161:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:instart’
    /usr/lib/ruby/1.8/webrick/server.rb:92:in each' /usr/lib/ruby/1.8/webrick/server.rb:92:instart’
    /usr/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/lib/ruby/1.8/webrick/server.rb:82:instart’
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
    dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire__’
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:inrequire’
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in
    require__' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire’
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
    `require’
    script/server:3

    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/form_options_helper.rb:114:in
    options_for_select' #{RAILS_ROOT}/app/views/layouts/application.rhtml:266:inrun_rhtml_layouts_application’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:314:in
    send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:314:incompile_and_render_template’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:290:in
    render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:249:inglobalize_old_render_file’
    lib/globalize/rails/action_view.rb:15:in render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/layout.rb:249:inrender_with_a_layout’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:738:in
    render_with_layout' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:689:inrender_action’
    #{RAILS_ROOT}/app/controllers/empresas_controller.rb:32:in buscar' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:insend’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in
    perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:inperform_action_without_benchmark’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
    perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:inmeasure’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
    perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:inperform_action’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in
    send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:inprocess_without_filters’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in
    process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:inprocess’
    #{RAILS_ROOT}/app/controllers/application.rb:29:in process' #{RAILS_ROOT}/app/controllers/application.rb:28:incatch’
    #{RAILS_ROOT}/app/controllers/application.rb:28:in process' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:indispatch’
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
    handle_dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:inservice’
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
    /usr/lib/ruby/1.8/webrick/server.rb:172:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:161:instart’
    /usr/lib/ruby/1.8/webrick/server.rb:161:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:instart’
    /usr/lib/ruby/1.8/webrick/server.rb:92:in each' /usr/lib/ruby/1.8/webrick/server.rb:92:instart’
    /usr/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/lib/ruby/1.8/webrick/server.rb:82:instart’
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
    dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire
    _’
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:inrequire’
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in
    require__' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire’
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
    `require’
    script/server:3
    Request
    Parameters: {“op”=>“Buscar”, “search_field”=>“companyname”,
    “search_value”=>“nombre empresa a buscar”}
    Show session dump

    Response
    Headers: {“Status”=>“200 OK”, “cookie”=>[], “Cache-Control”=>“no-cache”}

    Thanks for your aid.

    Greetings,

    Manuel Salguero
    Seville, Spain