Closed theycallmeswift closed 2 months ago
@theycallmeswift Hmmm, type_for_attribute
would be nice for ActiveModel generally. Have you considered a Rails PR to move type_for_attribute
from ActiveRecord up to ActiveModel? I'm not sure if it would be accepted, but other ActiveModel parts have followed that path, and the code seems to only use things already available in ActiveModel.
@theycallmeswift hey! Looks like Rails finally moved it to ActiveModel and it's going to be part of Rails 7.2 release https://github.com/rails/rails/pull/49910 so I'm closing this. Thanks for looking into it anyway!
Hey, folks!
I'm using Simple Form with some basic form objects that rely on the ActiveModel attributes API. Unlike ActiveRecord, ActiveModel classes do not benefit from automatic type detection because they don't implement
type_for_attribute
orhas_attribute?
.To achieve this behavior I've been adding the following to my models:
Would there be interest updating the
find_attribute_column
method to directly accessattribute_types
instead of going throughtype_for_attribute
?Relevant code:
https://github.com/plataformatec/simple_form/blob/aae6f9b6fd3983abc14eaddd410662c6c828ec10/lib/simple_form/form_builder.rb#L580-L586