I am generating some json to send to a web service.
Currently I am creating a hash, loading it with the data and then calling to_json to generate the json string to send.
But I figure it would be much cleaner and more rails like if I could use a template in a .erb file to generate the json for me.
All the info I can find on erb files use it to create data to send back to the client. I dont want to do this, I am the client here!
How can I do this?
ERB template engine is something you can use without Rails, actually.
In your case you can use a template like
Store it in a .erb file, read the contents with
File.openand then pass it toERB.new, like in the example.More info here: http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html