Search code examples
htmlruby-on-railsmailer

Rails: creating HTML files from form output


I'm trying to create an HTML file to be uploaded to a different server from a Rails app. I need a solution similar to a mailer in Rails. Does anyone know of a feasible way to achieve this?


Solution

  • If you are trying to send a file between servers, the easiest way is to create an API endpoint on the other server that allows uploading a file and use an API key to secure the connection. You could very easily use an HTTP POST method to perform the transfer (https://rubygems.org/gems/httmultiparty). If you need to generate the file first:

    data = render_to_string("post/show")
    HTTParty.post('http://other.host/posts', contents: data)