script in rails

You can create a rake task for that.