You can execute SQL statements in a rails application with the command:
ActiveRecord::Base.connection.execute(‘your sql’)
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-execute