It should be in model, plus its already in rails, to_csv should works out of box as I remember