Get model.create(params) to silently skip unknown attributes

Hi,

I have a remote website that will be sending me some data which I want
to save in one of my models. The problem is that it will also send some
attributes such as attribute_1, attribute_2, etc which I don't want to
save.

Currently if I do:

my_model.create(params), it will not pass as it has hash keys that don't
map to any attribute in the model, how to make my model skip these
unknown attributes in a clean manner?

Hi,

I have a remote website that will be sending me some data which I want
to save in one of my models. The problem is that it will also send some
attributes such as attribute_1, attribute_2, etc which I don't want to
save.

Currently if I do:

my_model.create(params), it will not pass as it has hash keys that don't
map to any attribute in the model, how to make my model skip these
unknown attributes in a clean manner?

You'd be better off cleaning up the params hash, eg with something
like

cleaned_params = params.slice(*Model.column_names)

Fred