RubyOnRails y MySQL2 devuelven el error 500 esporádicamente

I have a RubyOnRails application hosted on an Amazon EC2 server (with Elastic Load Balancer) that communicates with the database hosted on Amazon RDS.

I'm having trouble to fix the error 500 returned by the aplication sporadically:

NoMethodError (undefined method `fields' for nil:NilClass):
 activerecord (3.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:216:in `exec_query'

¿Cómo puedo solucionar este error?

preguntado el 24 de agosto de 12 a las 06:08

1 Respuestas

Most probably you are trying to call a method on a on an active record object that returned nil.

for instance if you have a model called page and are trying to get the fields for that page i.e. Page.find(params[:id]).fields however there os no record in the DB for a page with that id so you are trying to call the method fields on it which does not exist for that instance of your page model.

try wrapping the method call inside and if/else statement to call the method fields only if page(or whatever class you are trying to call it on) is not nil.

Respondido 24 ago 12, 18:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.