Extend column_for_attribute to work with form helpers (simple_form, etc)
peck opened this issue · 6 comments
Any interest in adding this to the gem itself? I find myself using using the following function in my models that I pass into simple_form builders to have the fields show up as the correct type, and not just default to text after receiving nil.
def column_for_attribute(attr)
atr = hstore_metadata_for_properties[attr]
if attr
OpenStruct.new(type: atr)
else
super(attr)
end
end
This seems useful. Can you create a PR with some tests?
Will do, have to work through some things downstream in the process for updating attributes and making sure all is good there, but yes, Ill put it on my to-do list and see what I can come up with.
Shouldn't use OpenStruct here, just create a regular Struct somewhere to avoid method cache busting every time an hstore class is used in a form build.
+1 for no OpenStruct. In fact, it should respect the original return type of column_for_attribute as closely as possible. While Struct/OpenStruct might meet the needs of simple_form, it could be surprising to someone expecting a different object.