@comments = []
@preComments = Comment.where(:resource_hash => resource_hash).
sort(:created_at.desc).all
@preComments.each do |comment|
newComment = comment
u = ::User.find_by_id comment.user_id
newComment.display_name = "Some name"
if u.image_location.nil?
newComment.image_location = "defaultpic"
else
newComment.image_location = u.image_location
end
p u
@comments << newComment
p "HERE!!!!!"
end
That’s my code, but I get an error saying
undefined method `display_name=' for #
So how do I assign a display_name?
Disclosure : I’ve never use MongoMapper
So my best bet is : just add
display_nameas part of theCommentschema. In models/comment.rb :end