I’m having problems with the relationships on a Rails 3 app. In the index view of one of my models I’m displaying a field from another model, and it is working perfectly locally, but when I push it to Heroku, I get the dreaded “We’re sorry, but something when wrong.” message. When I check the heroku log the error is “ActionView::Template::Error (undefined method `marca’ for nil:NilClass):”
This is the Marca Model:
class Marca < ActiveRecord::Base
has_many :modelos
has_many :vehiculos
end
This is the Modelo Model:
class Modelo < ActiveRecord::Base
belongs_to :marca
has_many :vehiculos
end
I’m trying to call f.marca.nombre in the Modelo index view, to display the field “nombre” from the table “marca”. I have a marca_id field in the Modelo table. The weird thing is that it works locally, and sometimes it works on heroku if I alter the order of the relationship lines in the model. Then after a few pushes to heroku, it stops working again.
I have tried running ‘Modelo.reset_column_information’ on heroku console.
Any suggestions? Should I do something to load changes in the model?
Thanks!
In the view you are doing this
f.marca.nombre. ‘nombre’ is a field in Marca. And you must be doing this in you new action of modelos_controller.Check marca for nil and whether marca.nombre is set? This is what is throwing the error.