Skip to content

Instantly share code, notes, and snippets.

@janko
Created July 28, 2015 00:09
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Insert statement in Arel
require "active_record"
ActiveRecord::Base.establish_connection("postgres:///db")
insert = Arel::Nodes::InsertStatement.new
insert.relation = Arel::Table.new(:movies)
insert.columns = hash.keys.map { |k| Arel::Table.new(:movies)[k] }
insert.values = Arel::Nodes::Values.new(hash.values, insert.columns)
ActiveRecord::Base.connection.execute(insert.to_sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment