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
endPara 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.injectExtracted 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:inrender_file' #{RAILS_ROOT}/app/controllers/empresas_controller.rb:32:in
buscar’
#{RAILS_ROOT}/app/controllers/application.rb:29:inprocess' #{RAILS_ROOT}/app/controllers/application.rb:28:in
catch’
#{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:in
send’
/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:in
render_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:in
render_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:in
render_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:in
perform_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:in
perform_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:in
perform_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:in
send’
/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:in
process_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:in
dispatch’
/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:in
service’
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in
run’
/usr/lib/ruby/1.8/webrick/server.rb:172:instart_thread' /usr/lib/ruby/1.8/webrick/server.rb:161:in
start’
/usr/lib/ruby/1.8/webrick/server.rb:161:instart_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in
start’
/usr/lib/ruby/1.8/webrick/server.rb:92:ineach' /usr/lib/ruby/1.8/webrick/server.rb:92:in
start’
/usr/lib/ruby/1.8/webrick/server.rb:82:instart' /usr/lib/ruby/1.8/webrick/server.rb:82:in
start’
/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: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’
/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:in
require’
/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:in
run_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:in
compile_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:in
globalize_old_render_file’
lib/globalize/rails/action_view.rb:15:inrender_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/layout.rb:249:in
render_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:in
render_action’
#{RAILS_ROOT}/app/controllers/empresas_controller.rb:32:inbuscar' /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:in
perform_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:in
perform_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:in
perform_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:in
send' /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:in
process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in
process’
#{RAILS_ROOT}/app/controllers/application.rb:29:inprocess' #{RAILS_ROOT}/app/controllers/application.rb:28:in
catch’
#{RAILS_ROOT}/app/controllers/application.rb:28:inprocess' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
dispatch’
/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:in
service’
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in
run’
/usr/lib/ruby/1.8/webrick/server.rb:172:instart_thread' /usr/lib/ruby/1.8/webrick/server.rb:161:in
start’
/usr/lib/ruby/1.8/webrick/server.rb:161:instart_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in
start’
/usr/lib/ruby/1.8/webrick/server.rb:92:ineach' /usr/lib/ruby/1.8/webrick/server.rb:92:in
start’
/usr/lib/ruby/1.8/webrick/server.rb:82:instart' /usr/lib/ruby/1.8/webrick/server.rb:82:in
start’
/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: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’
/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:in
require’
/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 dumpResponse
Headers: {“Status”=>“200 OK”, “cookie”=>[], “Cache-Control”=>“no-cache”}Thanks for your aid.
Greetings,
Manuel Salguero
Seville, Spain -