I am using Rails 4.1.4, Mongoid 4.0 and ruby 2.1.2p95. From my controller index that always returns undefined method `to_sym' for nil:NilClass. There are records in the database and from rails console, running thesame command @email_templates = EmailTemplate.all.to_a returns all the record in the database.
This is the controller index
class EmailTemplatesController < ApplicationController
def index
@email_templates = EmailTemplate.all.to_a
end
end
A shortened version of the Model
class EmailTemplate
include Mongoid::Document
field :name, type: String
field :subject, type: String
field :from, type: String
field :to, type: String
field :body, type: String
field :template, type: BSON::Binary
end
Why is this @email_templates = EmailTemplate.all.to_a working in rails console but returning error when called from the controller's index action.