title: Render file from controller
body: <p>I'm working on a grails application and struggling with rendering text to a file. Currently I can render the text to the screen with the function below which sits in the controller:</p>
  
  <pre><code>    def generateTemplateSQL(Template templateInstance){
  
      def result = templatingService.buildTemplateSql(templateInstance)
      render result
    }
  </code></pre>
  
  <p>Now I want to be able to print the same text to a file and this is what I have below. However the button on the front end that I've created for this function causes a 404 error once pressed. I'm guessing I've got something out of place. Any ideas?</p>
  
  <pre><code>    def writeTemplateSQLToFile(Template templateInstance){
  
      def result = templatingService.buildTemplateSql(templateInstance)
      render (file: new File(result), fileName: "TemplateSQL.met", contentType: "text/met")
    }
  </code></pre>