I have the following Rails model:
class CreateFoo < ActiveRecord::Migration def self.up create_table :foo do |t| t.string :a t.string :b
You can use Hash#slice and column_names method exists also as class method.
Hash#slice
column_names
hash = {a: 'some', b: 'string', c: 'foo', d: 'bar'} Foo.create(hash.slice(*Foo.column_names.map(&:to_sym)))