Hola a todos!
Amigos tengo un problema muy extraño con el find y que jamas me habia
ocurrido, el error me salio porque
porque coloque un id que no existe en la tabla articulos de mi BD (lo
hice para validar el sistema)
tengo este metodo en mi controller y como veran es algo secillo y
estupido
def report_stock
@articulo = Articulo.find(params[:id])
respond_to do |format|
if @articulo.blank?
flash[:error] = “El ID del Articulo indicado no esta registrado en
sistema”
return
else
format.html
end
end
end
Lo extraño es que si coloca un Id que si existe el metodo se ejecuta
excelente y me muestra mi vista sin problemas
pero si coloco un id que y sé que no existe resulta que me da el error
siguiente:
ActiveRecord::RecordNotFound in ArticulosController#report_stock
Couldn’t find Articulo with ID=555
RAILS_ROOT: /home/mwp/Proyectos MWP/sistema_adminprofit
Application Trace
http://localhost:3000/modificar_estado_proceso/555# | Framework
Trace http://localhost:3000/modificar_estado_proceso/555# | Full
Tracehttp://localhost:3000/modificar_estado_proceso/555#
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1383:in
find_one' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1366:in
find_from_ids’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:541:in
find' app/controllers/articulos_controller.rb:10:in
report_stock’ En esta
linea esta la instruccion ==> @articulo = Articulo.find(params[:id])
/usr/bin/mongrel_rails:128:in `run’
/usr/bin/mongrel_rails:244
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1383:in
find_one' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1366:in
find_from_ids’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:541:in
find' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:1166:in
send’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:1166:in
perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/filters.rb:579:in
call_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/filters.rb:572:in
perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/rescue.rb:201:in
perform_action_without_caching' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/caching/sql_cache.rb:13:in
perform_action’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
cache' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/query_cache.rb:8:in
cache’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/caching/sql_cache.rb:12:in
perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:529:in
send’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:529:in
process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/filters.rb:568:in
process_without_session_management_support’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/session_management.rb:130:in
process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:389:in
process’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:149:in
handle_request' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:107:in
dispatch’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:104:in
synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:104:in
dispatch’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:120:in
dispatch_cgi' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:35:in
dispatch’
/usr/lib/ruby/1.8/mongrel/rails.rb:78:in process' /usr/lib/ruby/1.8/mongrel/rails.rb:76:in
synchronize’
/usr/lib/ruby/1.8/mongrel/rails.rb:76:in process' /usr/lib/ruby/1.8/mongrel.rb:618:in
process_client’
/usr/lib/ruby/1.8/mongrel.rb:617:in each' /usr/lib/ruby/1.8/mongrel.rb:617:in
process_client’
/usr/lib/ruby/1.8/mongrel.rb:736:in run' /usr/lib/ruby/1.8/mongrel.rb:736:in
initialize’
/usr/lib/ruby/1.8/mongrel.rb:736:in new' /usr/lib/ruby/1.8/mongrel.rb:736:in
run’
/usr/lib/ruby/1.8/mongrel.rb:720:in initialize' /usr/lib/ruby/1.8/mongrel.rb:720:in
new’
/usr/lib/ruby/1.8/mongrel.rb:720:in run' /usr/lib/ruby/1.8/mongrel/configurator.rb:271:in
run’
/usr/lib/ruby/1.8/mongrel/configurator.rb:270:in each' /usr/lib/ruby/1.8/mongrel/configurator.rb:270:in
run’
/usr/lib/ruby/1.8/mongrel/command.rb:211:in `run’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1383:in
find_one' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1366:in
find_from_ids’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:541:in
find' app/controllers/procesos_controller.rb:10:in
modifedoproc’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:1166:in
send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:1166:in
perform_action_without_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/filters.rb:579:in
call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/filters.rb:572:in
perform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in
measure’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/rescue.rb:201:in
perform_action_without_caching’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/caching/sql_cache.rb:13:in
perform_action' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
cache’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/query_cache.rb:8:in
cache' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/caching/sql_cache.rb:12:in
perform_action’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:529:in
send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:529:in
process_without_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/filters.rb:568:in
process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/session_management.rb:130:in
process’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/base.rb:389:in
process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:149:in
handle_request’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:107:in
dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:104:in
synchronize’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:104:in
dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:120:in
dispatch_cgi’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:35:in
dispatch' /usr/lib/ruby/1.8/mongrel/rails.rb:78:in
process’
/usr/lib/ruby/1.8/mongrel/rails.rb:76:in synchronize' /usr/lib/ruby/1.8/mongrel/rails.rb:76:in
process’
/usr/lib/ruby/1.8/mongrel.rb:618:in process_client' /usr/lib/ruby/1.8/mongrel.rb:617:in
each’
/usr/lib/ruby/1.8/mongrel.rb:617:in process_client' /usr/lib/ruby/1.8/mongrel.rb:736:in
run’
/usr/lib/ruby/1.8/mongrel.rb:736:in initialize' /usr/lib/ruby/1.8/mongrel.rb:736:in
new’
/usr/lib/ruby/1.8/mongrel.rb:736:in run' /usr/lib/ruby/1.8/mongrel.rb:720:in
initialize’
/usr/lib/ruby/1.8/mongrel.rb:720:in new' /usr/lib/ruby/1.8/mongrel.rb:720:in
run’
/usr/lib/ruby/1.8/mongrel/configurator.rb:271:in run' /usr/lib/ruby/1.8/mongrel/configurator.rb:270:in
each’
/usr/lib/ruby/1.8/mongrel/configurator.rb:270:in run' /usr/bin/mongrel_rails:128:in
run’
/usr/lib/ruby/1.8/mongrel/command.rb:211:in `run’
/usr/bin/mongrel_rails:244
Request
Parameters:
{“id”=>“555”}
Revise por el log y rails me crea mi sentencia sql sin problemas
(select * from articulos where articulos.id = 555)
Lo que no logro entender es porque no entra al if @articulos.blank?
Nota: He probado con @articulo.nil y nada
Alguien me puede explicar?
Gracias