How to convert a transaction into hex before using the sendrawtransaction API? I've been trying to broadcast a transaction using sendrawtransaction of bitcoind.
I keep getting an error : "TX decode failed.", Code -22.

I suspect I'm not properly formatting the transaction into hex before attempting to send.

 btc.sendrawtransaction(new_tx.to_json.unpack("H*")[0])


Here is a representation of my transaction in hex :
         7b0a20202268617368223a22333235343463303630316532323932626566303039353265396636303437    38373665383637656336373664643036306163323365356563666361386135656335222c0a202022766572223a312c0a20202276696e5f737a223a312c0a202022766f75745f737a223a312c0a2020226c6f636b5f74696d65223a302c0a20202273697a65223a3139332c0a202022696e223a5b0a202020207b0a20202020202022707265765f6f7574223a7b0a20202020202020202268617368223a2239636239643035363965373135346662383565343538343162633564336663633734393961636431633831326264666565366535653961386433323933313664222c0a2020202020202020226e223a300a2020202020207d2c0a20202020202022736372697074536967223a22333034363032323130303935393761353761373036326537303762323830323439663662653831663434356263636663313038336264643231326465643231353961316534653137616330323231303065346163383535366362653237316163363631653965383364306439663564616333633032393330303263613836336230386431386236386434323361636461303120303333396535613566383031343165643664663566343436326461623831323161353461333365386163633161656235326639626264616465613138663033393963220a202020207d0a20205d2c0a2020226f7574223a5b0a202020207b0a2020202020202276616c7565223a22302
3031303030303030222c0a202020202020227363726970745075624b6579223a224f505f445550204f505f48415348313630203662343633623439373835393930386439646236\
3562393734623434333532386232396132613932204f505f455155414c564552494659204f505f434845434b534947220a202020207d0a20205d0a7ee


Is this how I transform a transaction into hex in ruby ?
Is there anything else I'm missing ?
You cannot convert json string to hex representation. Transactions have their own binary format (you can read in wiki: https://en.bitcoin.it/wiki/Transactions). To create transaction in hex format, you can use bitcoin-qt (or bitcoind) function createrawtransaction. Example of using:

createrawtransaction
'[
    { "txid": "10d5b7f61be2fa2e5979043a7071d3dbd371bc72cefea22e43b2dd54a6e27a99", "vout": 1 }
]'
'{
    "14rbFswzZfkPGkbFZ7Ffj2qhQA1omvgiUx": 0.099
}'


This call will return raw transaction in hex:

0100000001997ae2a654ddb2432ea2fece72bc71d3dbd371703a0479592efae21bf6b7d5100100000000ffffffff01e00f9700000000001976a9142a495afa8b8147ec2f01713b18693cb0a85743b288ac00000000


After that, you must call signrawtransaction:

signrawtransaction 0100000001997ae2a654ddb2432ea2fece72bc71d3dbd371703a0479592efae21bf6b7d5100100000000ffffffff01e00f9700000000001976a9142a495afa8b8147ec2f01713b18693cb0a85743b288ac00000000


This call will return raw transaction in hex, which you can send to network using sendrawtransaction.

Note: be very careful, you can make mistake in amount, and lose your bitcoins.