In a rails 4 (currently 4.0.10) application model I was having a problem with a method not defined for NilClass error in a view, and so I decided to try to solve by setting a sometime nil to an empty string in the model's after_initialize thusly:
def after_initialize
...
self.biography ||= ""
end
because, according to the docs here http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html , "after_initialize callback is triggered for each object that is found and instantiated by a finder" yet, it appears that after_initialize never gets called and so the error persists, as tested in the rails console:
2.1.1 :001 > Presenter.find(2) => #<Presenter id: 2, mediahub_id: 2, name: "Craig", asset_id: nil, biography: nil, status: "active", created_at: "2015-08-12 23:00:34", updated_at: "2015-08-12 23:00:34">
as you can see, biography is still nil after the find. What am I doing wrong? :)