Update documents_controller.rb

Moved code referencing model object into a lambda to prevent immediate evaluation.