I have the following Rails model:
class CreateFoo < ActiveRecord::Migration def self.up create_table :foo do |t| t.string :a t.string :b
Trying to think of a potentially more efficient way, but for now:
hash = { :a => 'some', :b => 'string', :c => 'foo', :d => 'bar' } @something = Something.new @something.attributes = hash.reject{|k,v| !@something.attributes.keys.member?(k.to_s) } @something.save